rid
rid

Reputation: 63542

How can I instantiate a Java generic with JNI?

If I want to instantiate a Date, 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>?

Upvotes: 10

Views: 3224

Answers (2)

Zach
Zach

Reputation: 897

@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

Upvotes: 7

Christoph Walesch
Christoph Walesch

Reputation: 2427

In the same way. On VM level, there are no generics.

Upvotes: 12

Related Questions