File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Errata ?

 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>();

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not failing to compile: it's a warning, not an error.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These warnings are mentioned later in the book, under Generics section
 
saloni jhanwar
Ranch Hand
Posts: 583
Firefox Browser Notepad Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kunal Lakhani wrote:These warnings are mentioned later in the book, under Generics section


nice.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic