On Mon, 18 Jan 2016 19:19:22 +0000, Voitech wrote: > Hi. I'm trying to parse an simple string expression to something like > Element array. Each Element can have a value of unknown type, which will > be further combined and calculated to let say real/double/float value, > no mather.
In Java, Element<T> is always Element<Object> behind the scenes, and there's only one type. In D, Element(T) is a template that produces a type. Element!int and Element!Object are entirely different and, thanks to what templates allow you to do, the compiler can't assume any relationship between the two. You have to establish that relationship manually by creating a base type: abstract class BaseElement { } class Element(T) : BaseElement { T value; } Alternatively, if this is not appropriate to your usecase, you may want to look at std.variant, which explicitly implements value boxing.