aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Autoboxing / unboxing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Autoboxing / unboxing" Watch "Autoboxing / unboxing" New topic
Author

Autoboxing / unboxing

Lalitha Gottumukkula
Ranch Hand

Joined: May 24, 2005
Posts: 45
This is compiled with jdk1.5.0_03


When compiled,

F:\practice\newjava>javac TestBoxing.java
Note: TestBoxing.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

F:\practice\newjava>javac -Xlint TestBoxing.java
TestBoxing.java:14: warning: [unchecked] unchecked call to add(int,E) as a member of the raw type java.util.ArrayList
l.add(0, new Integer(59));
^
TestBoxing.java:15: warning: [unchecked] unchecked call to add(int,E) as a member of the raw type java.util.ArrayList
l.add(1, num); // auto boxing
^
2 warnings

What are these warnings? What is an unchecked or unsafe operation?

Thanks,
Lalitha.
amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
what is auto boxing ???


Thanks and Regards, Amit Taneja
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
It is where an object that corresponds to a primitive is automatically cast by the system. This means you can assign an Instance of the Integer wrapper to an int value.


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
From http://java.sun.com/docs : New Java Language Features in JDK 5.0


"I'm not back." - Bill Harding, Twister
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
In order to avoid the warning, you can:



Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Lalitha Gottumukkula
Ranch Hand

Joined: May 24, 2005
Posts: 45
Is it compulsory to use generics in 1.5? Because, if I am commenting the autoboxing statement , then even it is showing warning with the other statement.


This code is working properly without any warnings in versions less than 1.5

Thanks,
Lalitha.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
It is "compulsory" to use 1.5 source level features when you are compiling with the 1.5 source level (logical isn't it?). There's no good reason not to (the "I don't understand it" reasoning is a bit silly).


Tony Morris
Java Q&A (FAQ, Trivia)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Autoboxing / unboxing