How can I instantiate a Java generic with JNI?
If I want to instantiate a D开发者_StackOverflow中文版ate
, I can use:
jclass cls = (*env)->FindClass(env, "java/util/Date");
jmethodID ctr = (*env)->GetMethodID(env, cls, "<init>", "()V");
jobject obj = (*env)->NewObject(env, cls, ctr);
But how do I instantiate an ArrayList<String>
?
In the same way. On VM level, there are no generics.
@noise is correct. Generics are used simply to ensure type safety. When compiled, the compiler does "type erasure". Check out this more detailed explanation of type erasure: Type Erasure
精彩评论