Questions tagged [boxing]

Boxing is the process of placing a primitive type within an object so that the primitive can be used as a reference object.

For example, storing a primitive integer in a data structure which can only store instances of class objects – that integer would need to be 'boxed' into an object and later 'unboxed' back into an integer.

5 questions
7
votes
2 answers

Generic request processing

I got a webservice that accepts multiple calls that require different handling and validation, using generics I've managed to create a common class that accepts a handler and a validator and it looks like this public class PetitionService
Zalomon
  • 1,200
  • 3
  • 8
  • 18
5
votes
2 answers

Is there a name for the number of values a variable can take?

For example, a bit or a boolean can be either 0 or 1 so the number 2 is associated with it. Similarly, for a byte which is 8 bits, the maximum number of different assignments would be 2^8. Is there a name for this number? When we pass everything…
Niklas Rosencrantz
  • 8,008
  • 17
  • 56
  • 95
4
votes
4 answers

When to not use dynamic in C#

I'm making a class similar to the following: public class KeyValue { public readonly string key; public readonly object value; } Value could be of any object type as a result of this design. Alternatively, I could just use dynamic for value…
9a3eedi
  • 2,101
  • 3
  • 23
  • 29
4
votes
6 answers

Do you have to have boxing of primitives in OO language?

Is boxing of primitives required in OO languages to keep them consistent with the rest of the object system (generics etc.)? Or is it avoidable - is it possible to avoid any additional performance cost of having both primitives and objects in a…
zduny
  • 2,623
  • 2
  • 19
  • 24
0
votes
2 answers

Is it acceptable to use C11 generic macros in Objective-C to box numbers?

I was getting tired of repeating types when writing things like this: NSDictionary* d = @{@"so": [NSNumber numberWithInt:index]), @"much": [NSNumber numberWithBool:accepted]), @"repeat": [NSNumber…
Craig Gidney
  • 831
  • 7
  • 16