Exception in thread "main" java.lang.NumberFormatException: For input string: "0x1" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:456) at java.lang.Short.parseShort(Short.java:120) at java.lang.Short.<init>(Short.java:331) at a.main(a.java:15)
Can somebody please explain? What are all the legal arguments for all the Wrapper objects? Are signs allowed?
Thanks in advance. Uttara Rishi.
[ March 10, 2008: Message edited by: Uttara Rishi ] [ March 10, 2008: Message edited by: Uttara Rishi ]
Hi, If you are trying to compare two objects then there will be no autoboxing happening. This is because of a wise decision by Sun that the code originally written without using autoboxing should not be affected.
That's the reason compiler gives an error when you try to compare the two objects which are incomparable.
Integer as = 303; long lo=303l; System.out.println(as==lo); // Line 1
The compiler will throw error in line 1 as compiler cannot unbox Integer and Type case it to Long at the same time.
Integer as = 30; Long lo=30L; System.out.println("==" +(as==lo)); Line 1// compiler error System.out.println(".equals" + (as.equals(lo))); // False will not compile as well as Integer and Long are two different classes Although both classes extends the Number Classs you cannot equate them using ==.