Java์์ Casting์ ๋ณ์๋ ํํ์์ ๋ฐ์ดํฐ ์ ํ์ ๋ค๋ฅธ ๋ฐ์ดํฐ ์ ํ์ผ๋ก ๋ณํํ๋ ํ๋ก์ธ์ค๋ฅผ ๋ํ๋ ๋๋ค. ์ด๋ ์๋ก ๋ค๋ฅธ ์ ํ ๊ฐ์ ํ ๋ณํ์ ์ํํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค. Java์์๋ ๋ ๊ฐ์ง ์ ํ์ ์บ์คํ ์ด ์์ต๋๋ค.
1) Widening Casting (automatically)
- converting a smaller type to a larger type siz
byte - short - char - int - long - float - double
2) Narrowing Casting (manually)
- converting a larger type to a smaller size type
double - float - long - int - char - short - byte
Casting is a way of converting data from one data type to another data type. By using casting, data cannot be changed but only the data type is changed
'Programming > Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
6 for loop (feat. Nested, foreach) (0) | 2024.01.07 |
---|---|
5 If & Switch (feat. break, continue) (0) | 2024.01.07 |
4 Operation (์ฐ์ฐ) (1) | 2023.12.30 |
2 Variable, Constant and Primitive Type in Java (Feat. Literal) (0) | 2023.12.29 |
1 JVM, JRE, JDK (0) | 2023.12.28 |
๋๊ธ