Wrapper를 쓰면 null을 저장할 수 있다.
Wrapper를 쓰면 함수를 사용할 수 있다.
*Inteser
Long d = 10L
package ex17;
class User {
private Long no;
private String name;
private Integer money;
// bin, bins 데이터 덩어리 Object와는 다름
// bins 만들땐 통상 int를 사용하지 않음.
public User(Long no, String name, Integer money) {
this.no = no;
this.name = name;
this.money = money;
}
public Long getNo() {
return no;
}
public String getName() {
return name;
}
public Integer getMoney() {
return money;
}
}
public class Wrap01 {
public static void main(String[] args) {
// 1. 회사운영 사원들의 정보 저장
User u = new User(1L, "홍길동", null);
//Wrapping을 해야 없는 값도 넣을 수 있음! null을 넣을 수 있는 것은 참조자료형뿐
}
}package ex17;
public class Wrap02 {
public static void main(String[] args) {
String s1 = "10";
Integer i1 = Integer.parseInt(s1); // 타입을 int로 변경
Integer i2 = 20;
String s2 = i2 + ""; // 문자열로
String s3 = i2.toString(); // 문자열로
}
}Share article