unboxing Questions
2
This code
public static int getValue(int key) {
return map.get(key);
}
private static Map<Integer, Integer> map;
static {
map = new HashMap<>();
map.put(1, 1);
map.put(2, 2);
}
...
7
Solved
Here is what I know about overload resolution in java:
The process of compiler trying to resolve the method call from given
overloaded method definitions is called overload resolution. If the...
Murielmurielle asked 7/5, 2015 at 18:44
6
What is the difference between boxing/unboxing and type casting?
Often, the terms seem to be used interchangeably.
9
Solved
I'm looking for a clear, concise and accurate answer.
Ideally as the actual answer, although links to good explanations welcome.
Vickyvico asked 16/8, 2008 at 8:34
6
Solved
I'm supposed to receive long integer in my web service.
long ipInt = (long) obj.get("ipInt");
When I test my program and put ipInt value = 2886872928, it give me success.
However, when I test my...
3
struct Point
{
public int x;
public int y;
}
void Main()
{
Point p;
p.x = 1;
p.y = 1;
Object o = p;
((Point) o).x = 4; // error
((Point) o).x = 5; // error
((Point) o).x = 6; // error
p =...
1
Solved
I have boxed tuple:
(int, string) tuple = (1, "abc");
object box = tuple;
How to obtain tuple from box? What is the right syntax to cast object back to tuple?
My attempt:
var deconstruct...
4
Solved
Since JDK 5.0, auto boxing/unboxing was introduced in Java. The trick is simple and helpful, but when I started testing different conversions between wrapper classes and primitive types, I get real...
Aguascalientes asked 25/3, 2014 at 23:41
2
Solved
Consider the following code
public class JDK10Test {
public static void main(String[] args) {
Double d = false ? 1.0 : new HashMap<String, Double>().get("1");
System.out.println(d);
}
}
...
1
Solved
I'm following the Android book example:
//Get the drink from the intent
int drinkIdd = (Integer)getIntent().getExtras().get(EXTRA_DRINKID);
Drink drink = Drink.drinks[drinkIdd];
And this projec...
Severson asked 11/4, 2018 at 3:51
10
Solved
I'm just revising chapter 4 of C# in Depth which deals with nullable types, and I'm adding a section about using the "as" operator, which allows you to write:
object o = ...;
int? x = o as int?;
i...
Ceyx asked 17/10, 2009 at 19:48
1
Solved
Unlike before, I was surprised to see that 'title' is now an optional (the compiler now generates the waning : String interpolation produces a debug description for an optional value; did you mean ...
Odericus asked 1/3, 2017 at 22:42
7
Solved
Boxing is the process of converting a value type into a managed heap object, which is implicit. Unboxing is the reverse process, for which the compiler requires an explicit cast. Since boxing store...
1
While pondering how to best map, i.e. traverse, an a -> Maybe a-Kleisli over an unboxed vector, I looked for an existing implementation. Obviously U.Vector is not Traversable, but it does supply...
Helminthic asked 19/1, 2017 at 13:40
8
At the run-time I get boxed instance of some type. How to unbox it to underlying type?
Object obj;
String variable = "Some text";
obj = variable // boxing;
// explicit unboxing, because we know ...
1
Solved
To illustrate my question, consider these trivial examples (C#):
object reference = new StringBuilder();
object box = 42;
object unset = null;
// CASE ONE: bad reference conversions (CIL instrcut...
3
Solved
I have this method:
private static Dossier PrepareDossier(List<List<object>> rawDossier)
{
return new Dossier((int)rawDossier[0][0]);
}
When I use it I get an InvalidCastException. ...
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
4
Solved
I have an IDataRecord reader that I'm retrieving a decimal from as follows:
decimal d = (decimal)reader[0];
For some reason this throws an invalid cast exception saying that the "Specified cast ...
1
Solved
I'm currently trying to convert an
Expression<Func<T,object>>
to an
Expression<Func<T,bool>>
Currently the watch shows me that my expression holds
Expression<Fu...
Saprogenic asked 17/11, 2015 at 9:38
2
I have this piece of code:
public void someMethod(String id) {
someOtherMethod(Integer.valueOf(id));
}
public void someOtherMethod(int id) {
// do something with id
}
And on that second line,...
2
Solved
FindBugs is giving me a warning about the following line, where invoiceNumber is an Integer object:
text.append(String.format("%010d-", (invoiceNumber == null) ? 0 : invoiceNumber));
The warning...
2
Solved
I have this function that checked the current value. When the current value (1st parameter) is null or empty, then it uses the default value you pass (2nd paramter)
public static T ZeroNull<T&g...
3
Solved
A colleague checked in this code:
Number n = ...;
double nr = n == null ? 0.0 : (double) n;
Another colleague then complained that this didn't compile, and that's what I would expect. However,...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.