Hi Ankur
I ran below code
It compiled fine and gave me output as 2.
If change code to add generics part as shown in below code
here i get compile time error which is expected as we are trying to add double value in a list that takes only Integer
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method add(Integer) in the type List<Integer> is not applicable for the arguments (double)
Hope it clears
Check which
Java version are you using to compile your code as Autoboxing feature was not present before Java 5 version. You might getting error because you may be running your code on lesser version of Java (Java 1.4,1.3 etc)
Oracle certified JPA Developer (1Z0-898),Oracle certified Java 8 Programmer I (1Z0-808), Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I, CIW Certified Ecommerce specialist