boxing Questions

9

Solved

Given a generic parameter TEnum which always will be an enum type, is there any way to cast from TEnum to int without boxing/unboxing? See this example code. This will box/unbox the value unnecess...
Chipmunk asked 27/7, 2009 at 16:18

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 =...
Yusuk asked 24/6, 2013 at 16:37

2

Let's say I'd like to ensure type safety in Java on primitive types. For the sake of an example, let us want to distinguish a Ratio from an AbsoluteValue, both are represented by a double. Java to...
Termless asked 30/10, 2019 at 9:26

17

Solved

This may be a bit of an easy, headdesk sort of question, but my first attempt surprisingly completely failed to work. I wanted to take an array of primitive longs and turn it into a list, which I a...
Villein asked 16/4, 2009 at 0:19

2

Solved

The documentation of constant pattern matching with the is-operator (expr is constant) states: The constant expression is evaluated as follows: If expr and constant are integral types, the C# equ...
Canella asked 12/6, 2019 at 11:56

7

Solved

I was doing some reading regarding boxing/unboxing, and it turns out that if you do an ordinary String.Format() where you have a value type in your list of object[] arguments, it will cause a boxin...
Heteromorphic asked 12/12, 2011 at 16:18

3

Solved

I'm curious about how C# behaves when passing value/reference types into a method. I'd like to pass a boxed value type into the method "AddThree". The idea is to get in the caller function (Main) t...
Demurrer asked 21/11, 2015 at 14:25

4

Solved

Why a generic method which constrains T to class would have boxing instructions in the generates MSIL code? I was quite surprised by this since surely since T is being constrained to a refer...
Barron asked 9/9, 2009 at 15:31

1

Solved

In the below code, the line System.out.println(sumInteger(bigs) == sumInteger(bigs)); displays as false. But when again we compare the another Integer wrapper classes System.out.println(bc ==...
Misdoing asked 25/1, 2019 at 11:0

4

Solved

I came across this and am curious as to why is it not possible to use the is operator to discern between bool and Nullable<bool>? Example; void Main() { bool theBool = false; Nullable<b...
Impose asked 10/1, 2019 at 12:4

2

Solved

I can think of two ways: public static IntStream foo(List<Integer> list) { return list.stream().mapToInt(Integer::valueOf); } public static IntStream bar(List<Integer> list) { retur...
Emmer asked 8/7, 2014 at 14:5

5

Solved

I have the following code in Java : class Boxing { public static void main(String args[]) { short s = 10; Integer iRef = s; } } Why does it produce an error in compilation? If I explicitl...
Amorphism asked 23/11, 2015 at 9:59

4

Solved

Is there a standard method I can use in place of this custom method? public static Byte[] box(byte[] byteArray) { Byte[] box = new Byte[byteArray.length]; for (int i = 0; i < box.length; i++)...
Harlin asked 6/4, 2010 at 15:3

2

Solved

I'm having trouble understanding how values of boxed traits come into existence. Consider the following code: trait Fooer { fn foo(&self); } impl Fooer for i32 { fn foo(&self) { println!...
Pecker asked 12/9, 2018 at 6:45

3

Solved

I have the following Java 8 code (simplified for demonstration): public Double fooBar(int a) { return Double.valueOf(a); } Now IntelliJ IDEA tells me that I have unnecessary boxing in the retur...
Tree asked 21/2, 2017 at 8:9

3

Solved

My question is somewhat related to this one: How does a generic constraint prevent boxing of a value type with an implicitly implemented interface?, but different because it shouldn't need a constr...
Indulgent asked 27/4, 2011 at 23:57

1

Solved

I'm trying to define a function that will take a reference as a parameter, and call a generic method on the referenced object, passing in a concrete value. I need a way of requiring that the generi...
Abrasion asked 9/7, 2018 at 14:14

5

Solved

Boxing is when a value type is assigned to an object type. Is it the same when a reference type is assigned to an object? When a type (which isn't object) is assigned, what happens? Is that boxin...
Alemannic asked 1/2, 2012 at 8:41

7

Solved

What is the difference between these two. I know Boxing is converting primitive values to reference. What is widening. Also what should be the sequence first boxing should be done or widening shoul...
Kristiekristien asked 22/10, 2010 at 9:53

3

Solved

Something just occurred to me earlier today that has got me scratching my head. Any variable of type Nullable<T> can be assigned to null. For instance: int? i = null; At first I couldn't ...
Geisler asked 23/9, 2010 at 5:12

1

Solved

This is a very specific and long question, but I'm not smart enough to figure it out by myself.. I was very intrigued by this YouTube-video from raywenderlich.com, which uses the "boxing" method t...
Kaye asked 2/5, 2018 at 13:22

2

Solved

Previously a question was asked about creating an array of functions where the functions returned integers from a range. The final solution was to do a map/collect into a Vec<_>. I have a s...
Tish asked 27/2, 2018 at 15:26

1

Solved

I looked around for this and could not find an answer. Say I have this code: class Command<T> : ICommand<T> { public void Execute(T parameter) { var isNull = parameter == null...
Mooncalf asked 8/2, 2018 at 12:45

5

Solved

Widening and Boxing Java primitives. I know it is not possible to widen a wrapper class from one to another as they are not from the same inheritence tree. Why though is it not possible to widen ...
Itinerate asked 10/8, 2011 at 16:15

4

Solved

in the Android Java world, is there a straighforward (ideally one-call) way to convert an array of int to an ArrayList<Integer> and back? Calling toArray() on the ArrayList returns an array o...
Crandale asked 19/5, 2011 at 20:31

© 2022 - 2024 — McMap. All rights reserved.