Code Comments
Programming Forum and web based access to our favorite programming groups.Hi
I'm trying to compile the following code, copied from the API (1.5.0)*:
Hashtable numbers = new Hashtable();
numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));
numbers.put("three", new Integer(3));
And I get the following error messages:
C:\KTH\algoritmer\HashtableTest.java:13: <identifier> expected
numbers.put("one", new Integer(1));
^
C:\KTH\algoritmer\HashtableTest.java:14: <identifier> expected
numbers.put("two", new Integer(2));
^
C:\KTH\algoritmer\HashtableTest.java:15: <identifier> expected
numbers.put("three", new Integer(3));
^
The way I understand it, Hashtable is generic (or whatever it's called) in
1.5, since it says Class Hashtable<K,V>.
But then how do I use Hashtable? The example code doesn't work. Or am I
doing something else wrong?
* http://java.sun.com/j2se/1.5.0/docs.../Hashtable.html
Regards
/Jimi
Post Follow-up to this messageJimi Hullegård wrote:
> Hi
>
> I'm trying to compile the following code, copied from the API (1.5.0)*:
>
> Hashtable numbers = new Hashtable();
> numbers.put("one", new Integer(1));
> numbers.put("two", new Integer(2));
> numbers.put("three", new Integer(3));
You tried to compile this, as shown, copied directly from the online
example? Did you wrap it in a class? Did you import anything? Where is the
rest of your code?
>
> And I get the following error messages:
>
> C:\KTH\algoritmer\HashtableTest.java:13: <identifier> expected
> numbers.put("one", new Integer(1));
> ^
> C:\KTH\algoritmer\HashtableTest.java:14: <identifier> expected
> numbers.put("two", new Integer(2));
> ^
> C:\KTH\algoritmer\HashtableTest.java:15: <identifier> expected
> numbers.put("three", new Integer(3));
> ^
>
> The way I understand it, Hashtable is generic (or whatever it's called) in
> 1.5, since it says Class Hashtable<K,V>.
> But then how do I use Hashtable? The example code doesn't work. Or am I
> doing something else wrong?
We can't tell. Post a complete, short example program that includes the
above snippet, so we can see it in context.
--
Paul Lutus
http://www.arachnoid.com
Post Follow-up to this messagePaul Lutus wrote: > Jimi Hullegård wrote: > > > You tried to compile this, as shown, copied directly from the online > example? Did you wrap it in a class? Did you import anything? >Where is the rest of your code? I'm terribly sorry. My misstake. Sure I imported everything needed and wrapped it in a class, but I forgot to wrap it in a method aswell... duh... hmm, I blame the late hour (1.30am). sorry! everything works now. /Jimi
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.