• Post Reply Bookmark Topic Watch Topic
  • New Topic

Recursive Methods  RSS feed

 
Paul Roberts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a type 1 greenhorn I have come to a grinding halt with the following code.



When trying to compile, the message 'RamConFig.java uses unchecked or unsafe operations' appears.

Typing javac RamConFig.java -Xlint:unchecked brings the messages:-

unchecked call to put <K, V> as a member of the raw type Hashtable

configs.put<Integer.toString<total>, new Integer<total>>;

where K<V are type variables:

K extends Object declared in class Hashtable

V extends Object declared in class Hashtable

Any words of wisdom would be much appreciated.

P.S. Why don't my Emoticons work?

[Edit - added code tags - MB]
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are type-safety warnings and can be ignored if you so choose.
The compiler generates these warnings, because the code doesn't use generics.
Have a look at this tutorial if you want to learn more about that subject: http://download.oracle.com/javase/tutorial/java/generics/index.html
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're getting that warning because it's suggesting you should use generic collections. Basically, replace:
with
On the other hand, given that example it seems fairly pointless to use a Hashtable at all, because you're just putting the same integer in as key and value (once as a String, the other as an Integer).
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, have a look at this tutorial.

http://download.oracle.com/javase/tutorial/java/generics/index.html
 
Paul Roberts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you kindly for your help. Your suggestions were all good. Also having a break enabled me to spot my act of gross stupidity. I

had been seeing the line 'public class RunConFig' and naming the file accordingly when actually the line is 'public class RunConfig'.

I'd be embarrassed if I wasn't so ashamed.
 
Paul Roberts
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While we're on the subject

Replacing the line 'static Hashtable configs = new Hashtable(64);'

with the line 'static Hashtable<String, Integer> configs = new Hashtable<String, Integer>();

produces a different set of results.

Is it safe to assume that the latter set of results are the correct ones?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!