autoboxing Questions

8

Solved

I'm implementing an interface that has functionality similar to a table that can contain an types of objects. The interface specifies the following function: double[] getDoubles(int columnIndex);...
Been asked 10/7, 2009 at 14:46

1

Solved

There is the following code: Integer time = 12; Double lateTime = 12.30; Boolean late = false; Double result = late ? lateTime : time; //Why here can I assign an Integer to a Double? System.out.pr...
Delaunay asked 23/1, 2017 at 10:19

4

I found a piece of code that after switching from Java 7 to Java 8 stopped compiling. It does not feature any of the new Java 8 stuff like lambda or streams. I narrowed the problematic code down t...
Mo asked 11/1, 2017 at 11:43

5

Solved

What is the most preferred way of converting a String to Long (the Object) in Java. Long a = new Long(str); OR Long a = Long.parseLong(str); Is there a correct way here because both see...
Hefty asked 29/9, 2016 at 14:57

8

Solved

Let's look at the simple Java code in the following snippet: public class Main { private int temp() { return true ? null : 0; // No compiler error - the compiler allows a return value of null ...
Lengel asked 11/11, 2011 at 19:30

1

Solved

In my software, I have some various values which use property delegation. This is a simple similar example showing what I do: class ExampleDelegate<T>(val value: T) { operator fun getValu...
Thad asked 25/8, 2016 at 18:20

3

Solved

What is the difference between the following: Integer in = (Integer)y; and Integer in = new Integer(y); I want to convert int type to Integer type and vice versa. Here is my code for doing that...
Zaragoza asked 4/7, 2016 at 5:53

2

Solved

We are using axis2 to generate web-service clients, (I regret this now!). With axis2 command-line tool you can pass switch -Euwc to wrap int into Integer, boolean into Boolean and so on in generate...
Parenthesize asked 31/5, 2011 at 14:21

10

Solved

I have a method like this: public static <T> boolean isMemberOf(T item, T[] set) { for (T t : set) { if (t.equals(item)) { return true; } } return false; } Now I try to call this met...
Kyongkyoto asked 5/2, 2009 at 20:24

4

Solved

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

3

I'm working on a program that deals constantly with gigabytes of data, mostly primitives and strings. I need to avoid having the primitives converted to Objects by autoboxing as this explodes the h...
Doctrinaire asked 19/3, 2016 at 23:32

5

Solved

Consider the following example: public static void main(String[] args) { double x1 = 0.0, y1 = -0.0; Double a1 = x1, b1 = y1; System.out.println(x1 == y1); //1, true System.out.println(a1.equa...
Indicatory asked 17/3, 2016 at 5:21

2

Solved

So I understand you can have object streams, i.e. Stream<T> and specialist primitive streams, e.g. IntStream, DoubleStream, etc. One of the benefits of the latter is to avoid autoboxing. Al...
Item asked 4/2, 2016 at 18:49

1

Solved

Is it the compiler or the runtime do the auto-boxing/unboxing? Consider the following example: public Integer get() { return 1; //(1) } At (1), the primitive integer value will be converted in...
Dosser asked 28/1, 2016 at 7:30

1

Solved

Say I have the following code: Map<String, Boolean> map = ... map.put("foo", true); Theoretically, true will have to be autoboxed, resulting in a slight performance hit versus inserting Bo...
Pseudohermaphroditism asked 8/1, 2016 at 23:8

0

When I put this into my avro schema: { "name": "the_id", "type": "int" }, And then I: mvn generate-sources A class file is generated that contains the following: private int the_id; /** * Al...
Weightlessness asked 18/12, 2015 at 14:27

15

Solved

I know there are similar posts on the topic, but they don't quite address my question. When you do: Integer a = 10; Integer b = 10; System.out.println("a == b: " + (a == b)); This will (apparent...
Hydrocellulose asked 11/3, 2011 at 20:20

5

Solved

Please regard the following lines of code: public static void main(String[] args) { foo(1,2,3); System.out.println("-------------------------------------"); foo(new Integer(1), new Integer(2), ...
Inherence asked 3/12, 2015 at 8:31

4

I'm trying to determine whether the following statements are guaranteed to be true: ((Boolean)true) == Boolean.TRUE ((Boolean)true) == Boolean.valueOf(true) ((Integer)1) == Integer.valueOf(1) I'...
Rabelais asked 16/7, 2015 at 3:44

2

Solved

Usually, treating a struct S as an interface I will trigger autoboxing of the struct, which can have impacts on performance if done often. However, if I write a generic method taking a type paramet...
Proper asked 16/7, 2015 at 14:52

5

Solved

I have a Java class of the following form: class Example { private byte[][] data; public Example(int s) { data = new byte[s][s]; } public byte getter(int x, int y) { return byte[x][y]; } pu...
Coley asked 3/4, 2013 at 15:11

3

Solved

The following code compiles (with Java 8): Integer i1 = 1000; int i2 = 1000; boolean compared = (i1 == i2); But what does it do? Unbox i1: boolean compared = (i1.intvalue() == i2); or box i2...
Forsooth asked 26/5, 2015 at 9:26

1

Solved

I have been studying Decorator pattern and developed simple class ToUpperCaseInputStream. I overrode read() method so it could convert all chars from InputStream to uppercase. Code of the method is...
Baxley asked 17/1, 2015 at 19:6

2

Solved

I am trying to formulate the rules that are being used in the scenarios below. Please explain why I am getting 2 different outputs. Scenario 1 output: I am an object. class Test { public static...
Fallow asked 14/1, 2015 at 10:7

1

Solved

I have a method that returns a Long object datatype via invocation of: resp.getResultCode(). I want to compare it HttpStatus.GONE.value() which actually just returns a primitive int value of 410. W...
Incursive asked 5/11, 2014 at 15:49

© 2022 - 2024 — McMap. All rights reserved.