开发者

How can I instantiate a Java generic with JNI?

开发者 https://www.devze.com 2023-03-02 16:45 出处:网络
If I want to instantiate a D开发者_StackOverflow中文版ate, I can use: jclass cls = (*env)->FindClass(env, \"java/util/Date\");

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

0

精彩评论

暂无评论...
验证码 换一张
取 消