Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java 5 JSlider compile issue  RSS feed

 
Chris Flynn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,



This compiles and works properly under 1.5.0, however the compiler throws the error "Track.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details."

and when I do that...

"Track.java:128: warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Hashtable
labelTable.put(new Integer(3), new JLabel("R"));"


As I said, it works, but is there any way to avoid this compiler warning? I know it's pedantic, but it'd be nice to see why it doesn't like it. As far as I see, my example is identical to that on http://java.sun.com/docs/books/tutorial/uiswing/components/slider.html ...


Cheers for your help - you guys rock.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your Hashtable is always going to have Integers as its keys and JLabels as its data, then you can (and should) declare it as such when you're using Java 5. Like this:And then, when you extract a reference from the Hashtable, you don't have to cast it:This is called "generics" and it's the main new feature in Java 5. If you google for "java generics tutorial" you should find a tutorial about it.
 
Chris Flynn
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great stuff - thanks for that
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!