aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Errata ? 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 "Errata ?" Watch "Errata ?" New topic
Author

Errata ?

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Book->K&B6->Chapter7->Page582
Code failed to compile with error given below

F:\OCJP\Chapter7\Set>javac SetTest.java
Note: SetTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

While it compiles and run when i declare type of HashSet
//HashSet<Object> s=new HashSet<Object>();



Tell the difficulties that i am difficult.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
That's because of generics.

While using collections, now you have a perfect reason for adding generics. Generics make it type safe, and moreover, you don't need to cast the return which you get from collections.


kunal
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4466
    
    8

That's not failing to compile: it's a warning, not an error.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

saloni jhanwar wrote:Book->K&B6->Chapter7->Page582
Code failed to compile with error given below

F:\OCJP\Chapter7\Set>javac SetTest.java
Note: SetTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

While it compiles and run when i declare type of HashSet
//HashSet<Object> s=new HashSet<Object>();



even if you use Hashset s = new HashSet() there won't be any compiler error . the program will compile and run. in above case what you are getting are just warnings. that is not compilation error. just compile with the compile time argument -Xlint:unchecked, then you will come to know exaclty which unsafe operation compiler is talking about.
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

gurpeet singh wrote:
saloni jhanwar wrote:Book->K&B6->Chapter7->Page582
Code failed to compile with error given below

F:\OCJP\Chapter7\Set>javac SetTest.java
Note: SetTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

While it compiles and run when i declare type of HashSet
//HashSet<Object> s=new HashSet<Object>();



even if you use Hashset s = new HashSet() there won't be any compiler error . the program will compile and run. in above case what you are getting are just warnings. that is not compilation error. just compile with the compile time argument -Xlint:unchecked, then you will come to know exaclty which unsafe operation compiler is talking about.


Yes, but book output hadn't these all warnings that's strange.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
These warnings are mentioned later in the book, under Generics section
saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

Kunal Lakhani wrote:These warnings are mentioned later in the book, under Generics section


nice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Errata ?