Java SE 6 and Autoboxing

I've only been working with Java for a few months so forgive me if i'm doing something dumb

Java SE 5, has an Autoboxing and unboxing feature that, as I understand it, one of the basic features is the ease of casting between primatives and their object equivalents. I have just upgraded to Java SE 6 and now all of the places that I have used this are failing saying that I um unable to convert between int and Integer for example.

So now

Integer temp = 0;

now needs to be something like:

Integer temp = Integer.valueOf(0);

And all the documentation says, as far as I can see is: Java SE 6 Properly Rejects Illegal Casts.

Does this mean this I have misunderstood the whole autoboxing thing is is there something I am doing wrong?

[782 byte] By [tuBrainsa] at [2007-11-27 3:09:29]
# 1

Determine whether this is a problem with your compiler or with your IDE.

Compile a small program using autoboxing at the command line. If it does not compile post the actual compiler message and the command you used.

If it does compile at the command line, but you get messages when you compile it from within an IDE, say what IDE you are using. And what settings you use.

pbrockway2a at 2007-7-12 3:58:26 > top of Java-index,Java Essentials,Java Programming...
# 2

You are correct. This seems to be an IDE issue not a compiler problem

The program I created is this:

public class test1 {

public static void main(String[] args) {

Integer one = 0;

String two = args[0];

one = Integer.parseInt(two);

System.out.println(one);

}

}

the error it gave is:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

Type mismatch: cannot convert from int to Integer

Type mismatch: cannot convert from int to Integer

at test1.main(test1.java:4)

I am using the Eclipse IDE Version: 3.2.2 Build id: M20070212-1330

I'm sorry I don't know what you mean by "What settings you use". I have not set any customisations I have literally just installed the Java SE 6 JDK then the Eclipde IDE.

The code worked fine compiling from the command line

tuBrainsa at 2007-7-12 3:58:26 > top of Java-index,Java Essentials,Java Programming...
# 3
In Eclipse from the Window menu choose "Preferences". On the right hand open up "Java" and select "Compiler". Check that "Compliance level" (near the top) is set to 6.0(I don't have Eclipse here, so this is from memory.)
pbrockway2a at 2007-7-12 3:58:26 > top of Java-index,Java Essentials,Java Programming...
# 4
Then you have an excellent memory.That seems to have fixed it. Thanks very much.
tuBrainsa at 2007-7-12 3:58:26 > top of Java-index,Java Essentials,Java Programming...
# 5
You're welcome.
pbrockway2a at 2007-7-12 3:58:26 > top of Java-index,Java Essentials,Java Programming...