Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news.cgarbs.de!news.addix.net!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Philipp Kraus Newsgroups: comp.lang.java.programmer Subject: Re: JNI generic type of jobject Date: Tue, 4 Oct 2011 14:49:02 +0200 Organization: 1&1 Internet AG Lines: 56 Message-ID: References: <4e8afbde$0$2529$e4fe514c@news2.news.xs4all.nl> NNTP-Posting-Host: p3ee2964c.dip0.t-ipconnect.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: online.de 1317732542 23258 62.226.150.76 (4 Oct 2011 12:49:02 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Tue, 4 Oct 2011 12:49:02 +0000 (UTC) User-Agent: Unison/2.1.5 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8520 On 2011-10-04 14:28:14 +0200, Silvio said: > On 10/04/2011 02:23 PM, Philipp Kraus wrote: >> Hello, >> >> I use JNI calls for some Java classes. Some Java classes are generic >> classes like: >> >> class mytestclass { >> >> public native void mymethod(); >> >> } >> >> The stub shows: >> >> JNIEXPORT void JNICALL Java_mytestclass_mymethod(JNIEnv* p_env, jobject >> p_object) >> >> How can I get from the jobject which object type is the generic >> parameter T? Because I would >> like to create different codes if I do something like: >> >> mytestclass x = new mytestclass(); >> x.mymethod(); >> >> mytestclass x = new mytestclass(); >> x.mymethod(); >> >> Thanks >> >> Phil >> >> > > No such thing is possible. Generics are a compile time thing. At > runtime only the raw types are available. Why? jobject is a pointer to the Java object that calls the JNI function, JNIEnv is also a pointer to the running environment, so I should get the type of the generic parameter, because the runtime / object knows them so within the JNI call the parameter must exists. I can also run in the Java class T.getClass().getName() and the Java code returns the name of the type the JNI call should do the same like JNIEnv->GetObjectClass( jobject.getTemplateVar(0) ) but I need the name / call of the "getTemplateVar(int)" function which gets an object to the first template parameter of the Java object Thanks Phil