I\'m writing a Java wrapper for c++ and would like to use a generic class to wrap a c++ template. Therefore I\'d like to get the generic type as String so I can further pass
Java generics don't preserve type information past compile time, due to type erasure. You need to pass an instance of T's class to your A class:
public class A<T>
{
private Class<T> type;
private long ptr;
public class A(Class<T> type)
{
this.type = type;
ptr = create( getGenericType() );
if(ptr == 0)
{
throw new NullPointerException();
}
}
private String getGenericType()
{
return type.getName();
}
private native long create(String className);
}