autoboxing Questions

5

There are instances where a method expects a primitive type double and you pass a Double object as a parameter. Since the compiler unboxes the passed object will this increase memory usage or dec...
Korwun asked 30/9, 2011 at 12:54

5

Solved

I wrote following code and was surprised to see the output: Integer a = 211; int b = 211; int[] array = {210,211,212}; System.out.println(Arrays.asList(array).contains(a)); System.out.print...
Scoot asked 17/9, 2014 at 12:39

4

Solved

Just spent a frustrating couple of hours debugging this code: LinkedHashMap<String, Integer> rsrqs = new LinkedHashMap<String, Integer>(); Integer boxedPci = 52; Integer boxedRsrq =...
Liberalism asked 21/8, 2014 at 2:36

1

final byte b = 12; Short s = b; Integer i = b; Program compiles fine for Short but for Integer compilation fails with "incompatible types" message. I am having difficult time trying to unders...
Croatian asked 13/8, 2014 at 17:27

1

Solved

Consider the following toy method: public Float testReturnFloat() { return 2f; } And the following client code: float resultOne = testReturnFloat(); Float resultTwo = testReturnFloat(); Do n...
Ubiquitous asked 21/5, 2014 at 13:21

2

Solved

I'm not looking to to turn off or ignore the warning as in The expression of type x is boxed into X?. I'd like to know what the correct way to handle/avoid this warning is if one was so inclined. ...
Popularly asked 27/4, 2014 at 0:0

3

Solved

Consider the following Java code: Integer foo = bar(); if(foo == 5) ...; if(5 == foo) ...; Are these comparisons equal -- particularly in the possibility of foo being null? Do they expand to foo...
Hesitancy asked 8/2, 2014 at 5:31

2

Solved

I'm working with an interface that takes type Object as its input. This is unfortunate for me as I have primitive data that I sometimes need to pass in through the interface. This of course forces ...
Abroach asked 2/8, 2011 at 3:7

3

Solved

I understand that auto un-boxing should be done with care because the reference that is being un-boxed can be null. Why is auto-boxing marked as warning as well? Are there some pitfalls I am missin...
Impetuosity asked 23/11, 2011 at 19:39

8

Solved

I want to convert a primitive to a string, and I tried: myInt.toString(); This fails with the error: int cannot be dereferenced Now, I get that primitives are not reference types (ie, not an ...
Loreeloreen asked 7/8, 2008 at 1:5

4

Solved

Do they both return the same thing i.e Long Class. Actually i was using this within PrivilegedAccessor to pass as following PrivilegedAccessor.invokeMethod(MyClass, "MyMethod", new Object[] { ar...
Gawk asked 30/1, 2014 at 18:4

5

Solved

public class T1 { public static void main(String[] args) { // TODO Auto-generated method stub Integer i1 = 1000; Integer i2 = 1000; if(i1 != i2) System.out.println("different objects"...
Turgot asked 26/12, 2013 at 12:12

4

Solved

I want to compare two Long objects values using if conditions. When these values are less than 128, the if condition works properly, but when they are greater than or equal to 128, comparison fails...
Ramonaramonda asked 12/12, 2013 at 10:59

5

Solved

When I do the following, arrayList1 - contains one element and it is an int[]. arrayList2 - not compiling (Error : The constructor ArrayList<Integer>(List<int[]>) is undefined) array...
Isolation asked 22/10, 2013 at 4:14

5

Solved

Can anyone explain why this code results in the below output? @Test public void testBooleanArray() { Boolean[] ab = new Boolean[]{a, b}; a = new Boolean(true); b = new Boolean(false); for(Bo...
Izzo asked 15/10, 2013 at 15:58

3

Solved

Here is the code i have to figure it out how is it possible. I have a clue but i do not know how to do it. I think it is about negative and positive numbers and maybe the variable modifiers a...
Geibel asked 27/9, 2013 at 3:51

3

Solved

Is the below (Java) code legal? class Test { Object foo() {return "";} boolean bar() {return foo() == true;} } It won't compile against JDK 6 but seems fine on 7+. Did the spec change? Was a b...
Circumjacent asked 11/9, 2013 at 1:56

1

I recently stumbled on a question that made me stop and think... To me, the code below should always trigger an error, but when one of my colleagues asked me why Eclipse didn't show one, I couldn'...
Brennan asked 29/8, 2013 at 0:0

4

My question involves wrapper classes. I know that when we store a primitive type literal by using wrapper classes, we are storing it as a object of that wrapper class so object's identifier will be...
Lanceted asked 23/8, 2013 at 12:49

7

public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here int a1 = 1000, a2 = 1000; System.ou...
Amide asked 28/7, 2010 at 10:9

2

Solved

Please, could you help me to understand why compilation of first call of testVargArgsAutoboxingPriority fails? In case of second call compiler is able to select proper method by preferring primiti...
Underskirt asked 13/7, 2013 at 17:53

2

Solved

The following code public class TestComparison { public static void main(String[] args) throws Exception { boolean b = true; Object o = new Boolean(true); System.out.println("comparison result...
Hourigan asked 27/5, 2013 at 9:42

2

Solved

Please consider 2 cases: //1 Short s = 10; //obviously compiles //2 takeShort(10); //error - int is not applicable //where: static void takeShort(Short s) {} I assume that case 1 is changed b...
Cinerarium asked 12/5, 2013 at 9:29

2

Solved

Here's an example: public boolean check(Class<?> clazz, Object o) { return clazz.isInstance(o); } check(int.class, 7); // returns false Since isInstance accepts an Object, it won't work ...
Policlinic asked 28/4, 2013 at 17:20

2

Solved

This prints false List vowelsList=Arrays.asList(new char[]{'a','e','i','o','u'}); System.out.println(vowelsList.contains('a'));//false This prints true List vowelsList=Arrays.asList(new Charact...
Monsignor asked 9/4, 2013 at 17:54

© 2022 - 2024 — McMap. All rights reserved.