Generics Problem

Hi,

I tried the following code(from an example)

public class Test {
private Integer i = new Integer(4);
private String s = new String("FFFF");
HashMap<Integer, String> hash = new HashMap<Integer, String>();
hash.put(i , s);
}

The has.put(i,s) gives the following errors:
"Cannot resolve Symbol put" and "Unknown class" for i and s.
I followed the installation procedures in the Help for Generics. Also Pallada happily does the auto-complete for the new HashMap (as per the test in the Help file).
Any suggestions will be much appreciated.


Also...just curious... but why, when using the jdk 1.5 beta, do we still need the jsr based collection.jar and gjc-rt.jar. Shouldn't these be in the 1.5 JDK?

Thanks

Trev...

10 comments
Comment actions Permalink

Hello!
>

I tried the following code(from an example)

>

public class Test {
private Integer i = new Integer(4);
private String s = new String("FFFF");
HashMap<Integer, String> hash = new HashMap<Integer, String>();
hash.put(i , s);
}

>

It becouse you should do thi within method body call:
public class Test {
private Integer i = new Integer(4);
private String s = new String("FFFF");
HashMap<Integer, String> hash = new HashMap<Integer, String>();
public void foo() {
hash.put(i , s);
}
}

or

public class Test {
private Integer i = new Integer(4);
private String s = new String("FFFF");
HashMap<Integer, String> hash = new HashMap<Integer, String>();
{
hash.put(i , s);
}
}

Thanks!


0
Comment actions Permalink

oops!....
thanks :)
Trev...

0
Comment actions Permalink

By the way you shouldn't be using implementation classes as types. :) At least, not for collections classes. This is considered better form:

 hash = new HashMap();]]>

0
Comment actions Permalink

>

Also...just curious... but why, when using the jdk 1.5 beta, do we still need the jsr based collection.jar and gjc-rt.jar.

Shouldn't these be in the 1.5 JDK?
>

You don't need collect.jar and gjc-rt.jar when using jdk 1.5. Just "-source 1.5" compiler flag

--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0
Comment actions Permalink

>> Also...just curious... but why, when using the jdk 1.5 beta, do we
>> still need the jsr based collection.jar and gjc-rt.jar.
>>

Shouldn't these be in the 1.5 JDK?

You don't need collect.jar and gjc-rt.jar when using jdk 1.5. Just
"-source 1.5" compiler flag


I get an error message sating cannot locate collect.jar in my Idea lib folder. Where should I put this compiler flag?
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

You need to turn off the "use generics-enabled compiler" checkbox. It shouldn't be looking for collect.jar.

0
Comment actions Permalink

You need to turn off the "use generics-enabled compiler" checkbox. It
shouldn't be looking for collect.jar.


Thanks

That got it!

scott
-- Posted by JetBrains OmniaMea

0
Comment actions Permalink

We'll fix this in Pallada - it will honor the check only for JDK 1.4 versions.

--
Best regards,
Eugene Zhuravlev
Software Developer
JetBrains Inc.
http://www.jetbrains.com
"Develop with pleasure!"



0
Comment actions Permalink

Hello Eugene,

We'll fix this in Pallada - it will honor the check only for JDK 1.4
versions.


So, you have two ways to use Generics -- use JDK 1.4 plus configuring the "Setup JSR014 Implementatin" wizard with downloadable Generics goodies -- AND -- simply using JDK 1.5 Beta (turning off 'use generics compiler' under compiler settings)?

David

0
Comment actions Permalink

"David Stennett" <david@nospamthankyou.com> wrote in message
news:c4c4rd$1hv$1@is.intellij.net...

Hello Eugene,

>

We'll fix this in Pallada - it will honor the check only for JDK 1.4
versions.

>

So, you have two ways to use Generics -- use JDK 1.4 plus configuring the

"Setup JSR014 Implementatin" wizard with downloadable Generics goodies --
AND -- simply using JDK 1.5 Beta (turning off 'use generics compiler' under
compiler settings)?


...and the second way you have to pass -source 1.5 to jdk1.5 javac.

P.S. Sorry for being wrong Eugene=)



0

Please sign in to leave a comment.