boxing Questions

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,...
Shockley asked 11/9, 2015 at 6:26

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...
Amaris asked 17/8, 2015 at 4:46

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

What is the purpose of using String.Concat(Object) instead of String.Concat(String) in C#? Why just not use an implicit call of Object.ToString() instead of passing an object itself that may also c...
Altimetry asked 31/7, 2015 at 7:45

4

I have made some ref keyword tests and there is one thing I can't understand: static void Test(ref int a, ref int b) { Console.WriteLine(Int32.ReferenceEquals(a,b)); } static void Main(string[] a...
Noyade asked 7/7, 2015 at 11:10

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...
Deepfry asked 22/5, 2015 at 6:46

2

Solved

I have the following return statement: public Boolean foo(String booleanString){ return ("true".equals(booleanString) ? true : ("false".equals(booleanString) ? false : null)); } when boo...
Nuncio asked 6/5, 2015 at 13:58

2

Solved

If we have a value that is already allocated on stack, will boxing copy it to heap and then transfer ownership (that's how it works in .NET, with the exception that both copies will stay alive)? Or...
Extra asked 13/4, 2015 at 22:7

3

Solved

Integer comparison in Java is tricky, in that int and Integer behave differently. I get that part. But, as this example program shows, (Integer)400 (line #4) behaves differently than (Intege...
Puzzler asked 8/4, 2015 at 12:51

2

Solved

I'm reading the book CLR via C# (4th edition), not as a newcomer to C# but as someone who knows the language trying to improve my grasp on the underlying functionality of the CLR. Anyway, in this ...
Heteroecious asked 11/3, 2015 at 19:30

2

Solved

In php-s type hinting, I cannot use scalar types, like integer, or string. So this is invalid: function myFunc(int $num) { //... } Is it possible to use wrapper classes, like in JAVA? Int...
Theron asked 17/11, 2014 at 11:54

1

Solved

Suppose I've got this Scala trait: trait UnitThingy { def x(): Unit } Providing a Java implementation is easy enough: import scala.runtime.BoxedUnit; public class JUnitThingy implements UnitT...
Dermatome asked 30/10, 2014 at 0:28

3

Solved

I have the Situation that I have an object which I want to check for equality with another object. public static bool Equals(object a, object b) { return a.Equals(b); } A Problem occurs when a ...
Recognizee asked 14/8, 2014 at 10:6

4

Solved

I understand what boxing is. A value type is boxed to an object/reference type and is then stored on managed heap as an object. But I can't get thru unboxing. Unboxing converts your object/referen...
Perisarc asked 30/7, 2014 at 11:11

1

Solved

Is it possible to force runtime boxing in scala dynamically? I would like a function: def box(value :Any) :AnyRef or def box[T](value :T) :AnyRef I have a generic class which may be paramet...
Actinology asked 15/7, 2014 at 11:27

1

Solved

I get the following error (VSC#2010 Express) on the declaration of GetChild method... Error 1 The type 'T' cannot be used as type parameter 'T' in the generic type or method '...Child'. There is n...
Vested asked 3/7, 2014 at 0:11

1

Solved

With the following code snippet: public static void Main() { int v = 2; Console.WriteLine("number" + "," + v); } Apparently it's better to replace v with v.ToString() in the call to WriteLine(...
Antipas asked 18/6, 2014 at 4:47

6

In the below code, the statement 1 throws casting exception. I am wondering why isnt it unboxing? The statement 2 works fine but I want to know why the first one is wrong? using (IDbCommand comman...
Ugaritic asked 18/10, 2011 at 6:40

6

When we convert the data types between primitive data types it is called as data type casting. But when convert between ValueType and ReferenceType we call it as boxing and unboxing. Can boxing ...
Sermon asked 16/7, 2012 at 21:21

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

3

Solved

In the C# Language Specification v5.0, in section 1.3, it says this: An Interface type can have as its contents a null reference, a reference to an instance of a class type that implements that...
Labiche asked 25/1, 2014 at 0:13

1

Solved

This is something I had not noticed until today. Apparently, the .NET implementation of the much used tuple classes (Tuple<T>, Tuple<T1, T2> etc) causes boxing penalties for value types...
Liqueur asked 13/1, 2014 at 5:25

1

Solved

Boxed nullable underlying type can be cast to enum but boxed enum type can't be cast to nullable type. And similarly, Boxed nullable enum can be cast to underlying type but boxed underlying t...
Rend asked 18/12, 2013 at 10:23

2

Solved

ECMA-335, 1.8.2.4, specifies that boxable types include reference types (excluding managed pointers/byrefs) and generic parameters. What is the purpose of boxing reference types? Is the functiona...
Knut asked 23/10, 2013 at 18:8

© 2022 - 2024 — McMap. All rights reserved.