autoboxing

sun vs eclipse autoboxing difference

I am trying to create a static entry to a bunch of non-static util methods and getting this error with the sun compiler that I am not getting in eclipse: "type parameters of X cannot be determined; no unique maximal instance exists for type variable X with upper bounds X,java.lang.Object" public class Resource { protected <X> X from...

Autoboxing/widening occurs in Short a=3 but not in Float a=3;

I understand that the following code won't work Float a=3 because its translated as Float a=Integer.valueOf(3). We'll have a Float reference on the LHS and an Integer object on the RHS, which is incompatible. But : 1. `Short a=3;` This works, though here again, we'll have a Short reference on the LHS and an Integer object on ...

Booleans, conditional operators and autoboxing

Why does this throw NPE public static void main(String[] args) throws Exception { Boolean b = true ? returnsNull() : false; // NPE on this line. System.out.println(b); } public static Boolean returnsNull() { return null; } while this doesn't public static void main(String[] args) throws Exception { Boolean b = true ?...

Error in the code

public class Test { Integer i; int j; public static void main ( String [] args ) { Test t = new Test (); t.go(); } public void go() { j=i; System.out.println(j); System.out.println(i); } } Output : Exception in thread "main" java.lang.NullPointerException at Test.go(Test...

Where do you put the parentheses to concisely convert a casted object to a primitive type without auto-unboxing?

With autounboxing, this statement will automatically work: int myPrimitive = (Integer) doIt(); But if I want to explicitly convert from an Integer to an int here in a single line, where do I have to put the parentheses? ...

Java auto boxing/unboxing wierdness

Possible Duplicates: Booleans, conditional operators and autoboxing Java, Google Collections Library; problem with AbstractIterator? The code below produces a NPE: Integer test = null; Integer test2 = true ? test : 0; System.out.println(test2); To correctly print out "null" without an exception requires this code: Intege...