Does D have object wrappers for primitives?

Cauterite via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 29 13:25:16 PDT 2016


On Friday, 29 July 2016 at 20:13:34 UTC, stunaep wrote:
> I have some java code I need to convert and at one point it 
> uses an Object[] array to store various ints, longs, and 
> strings. Java has built in Integer and Long classes that wrap 
> the primitives in an object and strings are already objects.

No, but with a template you could easily make your own:

class Boxed(T) {
	T _v;
	alias _v this;
	this(in T v) immutable {_v = v;};
};

auto i = new Boxed!int(6);


More information about the Digitalmars-d-learn mailing list