• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compile warning??  RSS feed

 
Jim Longmore
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I'm using the Stack object, and when I compile javac tells me that my class uses unchecked or unsafe operations.

When i compile with the -Xlint:unchecked flag, I get the following


What exactly does this mean? Can I fix it and still use the Stack class?
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,

This is because of the new Generics facility introduced in Java 5.
Basically it is asking you to change the 'type' of Stack to a particular type instead of the default 'Object' type.

So, if you are going to store String objects in the stack, change it to -


Now, if you try to insert something other than a String, say an Integer object, it will show up as a compile time error.

Hope that helped. If you google for 'Java generics'. you will get plenty of tutorials, articles etc.
 
Jim Longmore
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sonny.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!