Java
[Java] Wrapper 클래스
혀가 길지 않은 개발자
2020. 9. 28. 18:59
프로그래밍을 하다 보면 기본 타입의 데이터를 객체로 표현해야 하는 경우가 종종 있다.
public class JavaTest {
public static void main(String[] args) {
Integer integer = new Integer(123); // boxing
System.out.println(getNumber(integer));
Boolean bool = new Boolean(true); // boxing
System.out.println(getBoolean(bool));
Long lNumber = new Long(999999999999999999L); // boxing
System.out.println(getLong(lNumber));
String str = "James Kim";
System.out.println(str);
}
static int getNumber(Integer integer) {
return integer.intValue(); // unboxing
}
static boolean getBoolean(Boolean bool) {
return bool.booleanValue(); // unboxing
}
static long getLong(Long lNumber) {
return lNumber.longValue(); // unboxing
}
static String getString(String string) {
return string; // String의 primitive타입은 없음
}
}
