The moose likes IDEs, Version Control and other tools and the fly likes Collection specific elements not generic problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Collection specific elements not generic problem" Watch "Collection specific elements not generic problem" New topic
Author

Collection specific elements not generic problem

Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Hello Ranchers,

I am facing an error which is giving me a problem. I google it but it couldn't help.
I am running the Eclipse Europa on Windows vista with jdk & jre 1.6.
All the things works fine except:

Problem::

Following is my code:



I wanted to add only String values in the List not other type of values.
But,

It gives me compilation error at LINE 1 at the point of .

ERROR::
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token "<", invalid AssignmentOperator
Syntax error on token "=", != expected
Syntax error on token "<", ( expected
Syntax error on token "(", invalid Expression

at Ba.main(Ba.java:22)


When i use plain code like


When i use above line code it works fine.


What shall i have to do get rid of it. Because of this my whole developed project which i already done on Windows XP platform getting messed up.

Thanks in advance.


Perform for today. Adapt for tomorrow.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30936
    
158

Rahul,
It looks like you are compiling with an earlier version of Java. Can you confirm your project is using Java 1.4 in Eclipse?

This sounds like a tooling problem so I'll move it to our IDEs forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Originally posted by Jeanne Boyarsky:
It looks like you are compiling with an earlier version of Java. Can you confirm your project is using Java 1.4 in Eclipse?


I once again checked the version of the java by firing command
java -version in command prompt
and it shows java 1.6.0_04 version

Thanks again
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
What you have on command prompt and what you are using in Eclipse can be two very different things. Get the properties for the project you are working in on Eclipse, that might be using Java 1.4 compatibility.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30936
    
158

You might need to check in two places. The preferences for the Java project itself. And if it says "use defaults", you need to check the workspace preferences too.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Friends sorry in advance to ask you a simple question again

How can i see which JDK version i am using in Eclipse?

As you suggested i saw the settings in the Preference menu OR in Project properties
And i found jre 1.6 only in the Library tab of the Java Build Path.

Thank you.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30936
    
158

Originally posted by Rahul Shilpakar:
How can i see which JDK version i am using in Eclipse?

In the project preferences, go to the "java compiler" option. If "enable project specific settings" is checked, the version # is specified here. If the checkbox is not selected, the version # is in the workspace preferences under java --> compiler. These settings move around a bit in different versions of Eclipse - these locations are for Eclipse 3.3. They were nearby on prior versions, so you should see them in a similar location.

Note that the jar under the build path might not be the version of Java you are using. It's possible to compile against older versions of Java on a newer JVM.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Yes, You are right Jeanne Boyarsky.

Its compiling with older version (i.e. 1.4) of the JDK.

Now, what am i suppose to do so that my Java code will get compile with latest version (i.e. 1.6) of JDK which i already installed on my mahcine ?

Thank you.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Sorry for one incorrect information:

Earlier i mentioned that i am using Eclipse europa.
BUT, i am sorry.

I am using Eclipse 3.0 version.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30936
    
158

Rahul,
I don't believe Eclipse 3.0 supports Java 5. You'll need to upgrade to a later version of Eclipse to use the Java 5 features.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Rahul Shilpakar:

Now, what am i suppose to do so that my Java code will get compile with latest version (i.e. 1.6) of JDK which i already installed on my mahcine ?


Eclipse likely *is* already using your JDK. It is *never* using the compiler that is coming with the JDK, but uses its own one. So, to configure Eclipse to compile 1.6 code, you need to *both* point it to the right JDK *and* tell the *eclipse compiler* to act 1.6 compliant.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
originally posted by : Ilja Preuss
you need to *both* point it to the right JDK *and* tell the *eclipse compiler* to act 1.6 compliant.


how can i do that? I mean what are the steps to do that?

Thanks
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Rahul Shilpakar:


how can i do that? I mean what are the steps to do that?

Thanks


The steps that Jeanne already provided.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

There's also one more step, and it's very important. You have to actually install the desired JVM into Eclipse. On the Window/Preferences dialog, select Java/Installed JRE's, click the "Add" button and select the directory of the JVM you want to add. You can then select it as the default JVM for the workspace or as a selected JVM for a project.

As to whether or not Eclipse actually uses that compiler for workspace compiling, there seems to be some confusion. Allegedly Eclipse has its own compiler that's gimmicked up to integrate more closely with the IDE and the JRE is actually literally that - a JRE, not a JDK: used by the debugging phase.

As far as I can remember, Eclipse 3.0 supported Java 5, but not Java 6.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Orginally posted by Tim Holloway
As far as I can remember, Eclipse 3.0 supported Java 5, but not Java 6.


Yes, I tried all the things as said above.
And it does not support with JDK 6.Better i will change Eclipse.

Thanks all.
 
 
subject: Collection specific elements not generic problem