Wrapper를 쓰면 null을 저장할수있다.
Wrapper를 쓰면 함수를 사용할수있다.
int는 Integer로
Long d = 10L;
package ex17;
class User {
private Long no; //Long은 숫자뒤에 L을 붙임
private String name;
private Integer money;
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 user = new User(1L, "홍길동", null); //래핑으로 없는값 표현 가능
}
}
package ex17;
public class Wrap02 {
public static void main(String[] args) {
String s1 = "10";
Integer i1 = Integer.parseInt(s1);
Integer i2 = 20;
String s2 = i2 + "";
String s3 = i2.toString();
}
}
Share article