Re: Generics: struggling against type erasure...
z-man <nospam@nowhere.zz> writes:
Don't you think, anyway, that being forced by the language to
use the awkward factory pattern is much more a workaround than
an elegant solution?
If classes were more like objects, they could double as
factories themselves. (As Java is now, one needs to use
reflection to do this.)
Type parameters belong to a compile-time type system,
so they can not be known at run-time.
Java also has a run-time type system, insofar as every
object knows its class, but this information is not
available at compile-time.
(However, one could imagine a special pre-processor
for Java, that implements something like C++-templates.
It should know the static type of all arguments and
then create a special instance of a class declaration
for each call with the type parameter values hardwired.
In this case, an instance creation would be possible.
Given the huge amount of such tools, there is a chance
that such a program already exists somewhere.)