Re: Autoboxing Question Programming Software Development by JamesCherrill I knew I'd seen this before... [QUOTE]Autoboxing uses Integer.valueOf, which internally caches Integer objects for small … Re: Autoboxing Question Programming Software Development by NormR1 Good example of a potential problem with Autoboxing. i and j are objects but the compiler allows you to use them like primitives, EXCEPT for your example. BTW I don't care for compilers hiding things like this to save a few key strokes. Is the valueOf method called during autoboxing ? Programming Software Development by daudiam Is it true that during autoboxing, the type.valueOf() method is called (which creates a new object only if another with the same primitive constant is not in the intern list. This applies to cases where interning is allowed. Otherwise, it creates a new object using new() ). Is this right ? Re: Is the valueOf method called during autoboxing ? Programming Software Development by ~s.o.s~ [quote]Is it true that during autoboxing, the type.valueOf() method is called (which creates a new … Autoboxing Question Programming Software Development by BestJewSinceJC [CODE] Integer i = 5; Integer j = 5; if (i == j) System.out.println("true"); [/CODE] ^ Prints true [CODE] Integer i = new Integer(5); Integer j = new Integer(5); if (i == j) System.out.println("true"); [/CODE] ^ Does not print true. I understand that in the second case, the == is comparing the references. But why not in the… Re: Autoboxing Question Programming Software Development by JamesCherrill Because Integers are final, and can't change, maybe the compiler optimises by creating one Integer(5) and pointing both refs at it (like Strings). ? ??? Re: Autoboxing Question Programming Software Development by ~s.o.s~ [URL="http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.7"]Relevant section in the Java specification.[/URL] Re: Autoboxing Question Programming Software Development by NormR1 Thanks for the link. Re: Autoboxing Question Programming Software Development by BestJewSinceJC Very useful link s.o.s. and thanks everyone for the replies. To summarize (for anyone who comes to this thread at a later date) I tested the theory of s.o.s's link by using [CODE] Integer i = 127; Integer j = 127; if (i == j) System.out.println("true"); [/CODE] And it prints true, but [CODE] Integer i = 128; Integer j = 128; if (i == j… Re: Is the valueOf method called during autoboxing ? Programming Software Development by daudiam Thanks Generics and += Programming Software Development by sciwizeh … tried to make sure that it extends number, but the autoboxing doesn't seem to work with generics. can anyone help… Re: Generics and += Programming Software Development by masijade … classes that extend Number can use those operators (only through autoboxing of course, which Number, of course, also can't do… Casting of int[] to Object[] Programming Software Development by legilimen … (Object a){ } main(){ call(10); } [/CODE] it works because of autoboxing But why didn't the language designers support something like… getClientproperty Programming Software Development by scheppy … value btw, im using java 1.4.2, so no autoboxing I know how to get int values, and here is… INTs not getting interned during autoboxing Programming Software Development by daudiam I understand that int values, when autoboxed, are interned i.e no 2 objects containing the same int are present, and so we can compare two Integers by == So why does the following happen :[CODE]Integer iRef1=1000; Integer iRef2=1000; System.out.println(iRef1 == iRef2); System.out.println(iRef1.equals(iRef2));[/CODE] This prints [CODE]false true[/… Re: INTs not getting interned during autoboxing Programming Software Development by daudiam Sorry, I failed to notice that INTs are interned only when they are in the range of -128 to 127 Re: Arrays and ArrayList Programming Software Development by masijade … its elements as if it were an int, thanks to autoboxing, but if you want a real int array, you will… the Integer[]) into the int[] (you can, once again, let autoboxing make the conversions, but you will have to copy the… Re: how many of you use 1.5? Programming Software Development by jwenting … if you do a lot of looping (which we do). Autoboxing and unboxing can save quite a bit of typecasting (at… Re: UnsupportedFlavorException??? Programming Software Development by jwenting … not an Object. In 1.5 a new feature called autoboxing/unboxing was introduced that allows you to treat primitives like… Re: New 2 JAVA Programming Software Development by Phaelax …[/URL] wrapper for this).[/quote] Doesn't 1.5 have autoboxing? (I still use 1.4 so I'm not sure… Re: New 2 JAVA Programming Software Development by Infarction [quote=Phaelax;251423]Doesn't 1.5 have autoboxing? (I still use 1.4 so I'm not sure)[/quote] I don't remember for sure (it's been several months since I've used Java), but I thought it didn't. Could very well be wrong on that, though. Re: New 2 JAVA Programming Software Development by jwenting 5.0 has autoboxing. P.S I h8 it when kids use h@x0r 5pe@k. Re: unexpected type error Programming Software Development by jwenting char is a primitive, you can't store primitives in Collections. Make it Set<Char> instead, and autoboxing will ensure your chars are converted into Chars and back again. Re: unexpected type error Programming Software Development by Covinus …>s = new HashSet<Char>(); ^ 2 errors whats autoboxing??? Re: two dimensional arrays Programming Software Development by masijade … do array[i][j] = 1; or some other int, because autoboxing will automatically convert it to an Integer. You can also… Re: two dimensional arrays Programming Software Development by anamika_nagpur … do array[i][j] = 1; or some other int, because autoboxing will automatically convert it to an Integer. You can also… Re: Arraylist of long Programming Software Development by Ezzaral You need ArrayList<Long>. Long is the wrapper class for the primitive long. Autoboxing will convert your long values to Long for you when you add them to the ArrayList. Re: Need guidance Programming Software Development by Ezzaral … to pass that Double in place of a double parameter (autoboxing). You can use Double.parseDouble(String) to convert direct from… Re: instantiation; and arrays & structures really objects? Programming Software Development by Rashakil Fol … and return a reference to that copy. (This is called autoboxing.) If the type of the variable x is a reference… Re: Garbage collection in java Programming Software Development by masijade … you did not generitise that list with <Integer>, autoboxing will not happen (the VM does not autobox to Object…