17. AutoBoxing, Unboxing(JDK 1.5)
Wraping의 번거로움을 해결한 과정.
일일이 Implicit, Explicit Casting하였지만 직접 대입해도 무관
Ex 1 :
1 2 3 4 5 | int intValue = 1; ArrayList<Integer> arrayList = new ArrayList<Integer>(); arrayList.add(intValue); //==>autoboxing int i = arrayList.get(0); //==>autounboxing | cs |
Ex 2 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public void add15(int intValue,double doubleValue,boolean boo){ //==> Autoboxing 기능 이해 :: Method add14() 비교 Integer i = intValue; // 내부적수행 ==>Integer i = new Integer(intValue); Double d = doubleValue; // 내부적수행 ==>Double d = new Double(doubleValue); Boolean b = boo; // 내부적수행 ==>Boolean b = new Boolean(boo); //==>각각의 출력하면... System.out.println("i.toString() : "+i); System.out.println("i.intValue() : "+i.intValue()); System.out.println("d.toString() : "+d); System.out.println("d.doubleValue() : "+d.doubleValue()); System.out.println("b.toString () : "+ b); System.out.println("b.booleanValue() : "+ b.booleanValue()); //==> Auto-unboxing 기능 이해. double result = i+d; //내부적수행 ==>i.intValue()+d.doubleValue(); System.out.println("합 : "+result); } | cs |
반응형
'Java > Theory' 카테고리의 다른 글
[Java/Theory]19. interface기반, Inner class, instanceof (0) | 2016.05.31 |
---|---|
[Java/Theory]18. Exception Handling (0) | 2016.05.31 |
[Java/Theory]16. Data Structure (0) | 2016.05.31 |
[Java/Theory]15. StringBuffer, Calander, WrapperClass (0) | 2016.05.31 |
[Java/Theory]14. Object (0) | 2016.05.31 |