데이터 타입
변수가 보유할 수 있는 값의 종류와 수행할 수 있는 연산을 지정하는 분류.
데이터 타입은 변수에 저장할 수 있는 데이터의 성격과 허용되는 연산을 정의합니다. 타입은 올바른 데이터 처리를 보장합니다.
기본 타입(Primitive):
- 정수(Integer): 정수 (int, long)
- 실수(Float/Double): 소수
- 불리언(Boolean): 참/거짓
- 문자(Char): 단일 문자/기호
- 문자열(String): 문자들의 시퀀스
복합 타입(Composite):
- 배열(Array): 동일한 타입의 요소 모음
- 객체(Object): 사용자 정의 구조
- 구조체(Struct): 명명된 필드 그룹
타입 시스템:
- 정적 타이핑: 컴파일 시 확인 (Java, C++)
- 동적 타이핑: 런타임 시 확인 (Python, JavaScript)
- 강한(Strong) 타이핑: 엄격한 타입 규칙
- 약한(Weak) 타이핑: 자동 타입 변환
graph LR
Center["데이터 타입"]:::main
Rel_boolean["boolean"]:::related -.-> Center
click Rel_boolean "/terms/boolean"
Rel_data_modeling["data-modeling"]:::related -.-> Center
click Rel_data_modeling "/terms/data-modeling"
Rel_data_structure["data-structure"]:::related -.-> Center
click Rel_data_structure "/terms/data-structure"
classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
linkStyle default stroke:#4b5563,stroke-width:2px;
🧒 5살도 이해할 수 있게 설명
데이터 타입은 서로 다른 용기와 같습니다. 돼지 저금통은 동전(숫자)을, 책장은 책(문자열)을, 신호등은 빨강/초록(불리언)을 담습니다. 각 용기는 제 짝이 있습니다!
🤓 Expert Deep Dive
Hindley-Milner 타입 추론은 주석 없이 정적 타이핑을 가능하게 합니다. 대수적 데이터 타입(합/곱 타입)은 강력한 모델링을 가능하게 합니다. 의존 타입(Idris, Agda)은 제약 조건을 타입에 인코딩합니다. 점진적 타이핑(TypeScript)은 정적과 동적을 연결합니다. 타입 소거(Type erasure)는 런타임에 타입을 제거합니다(Java 제네릭).