autoboxing Questions

4

Solved

Can someone explain to me the usage of Integer, Boolean etc in place of their primitive types in JAVA? I can't seem to grasp the advantages their are providing. They seem to create unnecessary pro...
Laforge asked 21/5, 2010 at 6:14

2

Solved

Consider the following snippet: int i = 99999999; byte b = 99; short s = 9999; Integer ii = Integer.valueOf(9); // should be within cache System.out.println(new Integer(i) == i); // "true" ...
Godfrey asked 14/5, 2010 at 5:6

1

Thanks to the implicit casting in compound assignments and increment/decrement operators, the following compiles: byte b = 0; ++b; b++; --b; b--; b += b -= b *= b /= b %= b; b <<= b >>...

2

Solved

How can we new primitive types in JNI. I have a function that returns a jobject. It is possible to return jint, jchar, etc. There is NewString, why not NewInteger, NewCharacter, NewDouble, etc. T...
Kilian asked 22/3, 2010 at 21:6

3

Solved

Why is the second piece of code faster? Map<Integer, Double> map = new HashMap<Integer, Double>(); for (int i = 0; i < 50000; i++) { for (double j = 0.0; j < 10000; j++) { map....
Window asked 21/2, 2010 at 23:28

14

Solved

I have a function that returns an id number if the argument exists in the database. If not, it returns null. Is this begging for a null pointer exception? Negative id numbers are not permitted, but...
Catechize asked 24/1, 2010 at 19:27

4

Solved

I am a big fan of auto-boxing in Java as it saves a lot of ugly boiler plate code. However I have found auto-unboxing to be confusing in some circumstances where the Number object may be null. Is t...
South asked 9/1, 2010 at 13:28

4

Solved

So I was asked this question today. Integer a = 3; Integer b = 2; Integer c = 5; Integer d = a + b; System.out.println(c == d); What will this program print out? It returns true. I answered it w...
Gladwin asked 7/1, 2010 at 15:29

2

Solved

This gives me an error: int[] l = new int[] {0, 2, 192, -1, 3, 9, 2, 2}; int[] l2 = new int[] {9001, 7, 21, 4, -3, 11, 10, 10}; int[] l3 = new int[] {5, 5, 5, 64, 21, 12, 13, 200}; Set<List&lt...
Unprofitable asked 20/11, 2009 at 14:46

2

Solved

I am manually converting code from Java (1.6) to C# and finding some difficulty with the behaviour of primitives (int and double). In C# it appears that almost all conversions happen automatically ...
Attainable asked 20/10, 2009 at 20:38

6

Solved

I have heard of types being referred to as "boxed" in some languages. In Java, I have heard of "autoboxing". What is this? Is it having wrapper classes for a type? How would my code change if I'm...
Cultus asked 13/9, 2009 at 17:23

9

Solved

Autoboxing seems to come down to the fact that I can write: Integer i = 0; instead of: Integer i = new Integer(0); So, the compiler can automatically convert a primitive to an Object. Is ...
Stickweed asked 20/4, 2009 at 0:16

4

Solved

When the Java compiler autoboxes a primitive to the wrapper class, what code does it generate behind the scenes? I imagine it calls: The valueOf() method on the wrapper The wrapper's constructor ...
Crunode asked 3/1, 2009 at 5:32

1

Solved

Is it possible to implement autoboxing for your own classes? To illustrate my example, this is what I might want to write: Foo foo = "lolcat"; And this is what Java would do (as per my own defi...
Moonstone asked 4/11, 2008 at 8:17

3

Solved

I saw this in an answer to another question, in reference to shortcomings of the Java spec: There are more shortcomings and this is a subtle topic. Check this out: public class methodOverloading{ ...
Gotcher asked 7/8, 2008 at 16:30

© 2022 - 2024 — McMap. All rights reserved.