J
joehust
I have a class like this:
class Test<T>{
class Test<T>{
You can't. This was done on purpose and is called "type erasure". T isString here in Test's constructor
You can't. This was done on purpose and is called "type erasure". T is
a purely compile time notion. All trace of it is erased from the
object file, so there is nothing for the rune time to get a grip on.
I have a class like this:
public class Test<T>{
public Test() {
// TODO : get the actual type of T
}
}
Test<String> a = new Test<String>();
// could I write code like this? How to get the type of T which is
String here in Test's constructor
Lew said:One trick in the literature is to pass in or create a Class<T> member of
the class to use as a type marker.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.