The lines/snippet you posted compile(s) and run(s) okay.
You mentioned an error for the return value of the
put method. If I modify your code to explore this
Hashtable<String, Integer> numbers= new Hashtable<String, Integer>();
numbers.put("one", 1);
int m = numbers.put("two", 2); // runtime error
Integer n = numbers.put("three", 3); // okay
the line with "int m = ..." (line 7) throws a NullPointerException:
C:\jexp>java Test
Exception in thread "main" java.lang.NullPointerException
at Test.main(test.java:7)
j2se 1.5+ has autoboxing which can cause trouble. The
put method takes
Objects for both key and value. Your Hashtable declaration specifies String(key) and Integer(value) which, according to the javadoc for the class api, will then return an Integer. So if you want a return value from the
put method you will need an Integer (vis–a–vis an
int primitive data type) to receive it (as shown above).