PDA

View Full Version : strange error using generics in java on ubuntu



the_real_fourthdimension
October 3rd, 2009, 06:52 PM
Hey All

I get a really strange error when I try to use generics in java on 9.04. My code:


private ArrayList<myType> list = new ArrayList<myType>();

and the error:

Syntax error, parametrized types are only available if source level is 1.5
Do I need to update javac?

NovaAesa
October 4th, 2009, 12:29 AM
Generics have only existed in Java since version 5.0 (which is the same version at 1.5, they did a weird version thing).

You can find out the versions of java you have by using the following code
update-java-alternatives -l You will want to see
java-6-sun 63 /usr/lib/jvm/java-6-sun there as one line. If it's not there, you need to install Sun's java (I have found it to be the best for coding, as it is both the dejour and defacto implementation). You can install it with
apt-get install sun-java6-jdk sun-java6-jre sun-java6-bin Once that is installed (or if it was already installed) you need to switch the java and javac commands so they actually work with the correct compiler. This can be done with
update-java-alternatives -s java-6-sun

Hope this helps!

NovaAesa
October 4th, 2009, 07:35 AM
By the way, are you trying to compile from the command line? or inside of an IDE? (this will make a difference as to what you have to do to fix the problem).