Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- MIPS
- html
- CSS
- instruction
- Pipelining
- php
- DS
- mysql
- web
- DATAPATH
- control
- system
- Linux
- DB
- while
- function
- Algorithm
- architecture
- Java
- react
- for
- DoM
- computer
- python
- data structure
- XML
- github
- MacOS
- Class
- javascript
Archives
- Today
- Total
YYYEJI
[JAVA] 형변환(Casting) 이란? 본문
728x90
JAVA에서 변수의 타입을 변경할 때 사용하는 방법으로 두 가지가 있습니다.
① Implicit casting
② Explicit casting
Data type의 계층입니다.
Byte → short → int → long → float → double
1bytes → 2bytes → 4bytes → 8bytes → 4 bytes → 8btyes
Implicit casting
• 직접 선언해 주지 않아도 타입을 자동으로 바꿔주는 형변환 입니다.
• 큰 타입에 넣는 경우에는 자동으로 타입을 바꿔줍니다.
double x;
int n = 5;
x = n;
Explicit casting
• (<data type>) variable_name
• 변환할 타입을 직접 선언해줘야 되는 형변환 입니다.
• 더 작은 타입에 집어 넣는 경우에 명시적으로 타입을 지정해줘야 됩니다.
int x;
double n = 5;
x = n; # Error
x = (double)n;
• n의 값에서 형변환이 일어나는 것이 아니라 return value가 형변환이 되어 return됩니다.
◡̈
'Java' 카테고리의 다른 글
[JAVA] Truncates 란? (0) | 2022.10.23 |
---|---|
[JAVA] String 클래스 매소드 정리 (0) | 2022.10.23 |
[JAVA] Primitive data type의 종류 (0) | 2022.10.22 |
[JAVA] 예약어와 키워드의 차이점 (Keyword, Reserved word) (0) | 2022.10.22 |
[JAVA] 변수 타입의 종류 (Primitive type, Class type) (0) | 2022.10.22 |