4 ms·
I haven't seen anyone mention it yet, so I'll just point out that the kind of userland reification described in this article is also possible in Scala using imp
by nicktelford 8y ago
I haven't seen anyone mention it yet, so I'll just point out that the kind of userland reification described in this article is also possible in Scala using implicits:
class List[T](implicit tag: ClassTag[T]) {
def elementType: Class[_] = tag.runtimeClass
}
You can do something similar for your own types in Java, albeit with less help from the compiler:
public class List<T> {
private final Class<T> t;
public List(final Class<T> t) {
this.t = t;
}
public Class<T> elementType() {
return this.t;
}
}
The problem is that you rarely own the definition of all the types you want/need to reify.