This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Re: invoking package-private constructor from native code
- To: Oskar Liljeblad <osk at hem dot passagen dot se>
- Subject: Re: invoking package-private constructor from native code
- From: Tom Tromey <tromey at cygnus dot com>
- Date: 16 Sep 2000 10:57:16 -0600
- Cc: java-discuss at sourceware dot cygnus dot com
- References: <20000916121200.A30292@strix.eductussyd.se>
- Reply-To: tromey at cygnus dot com
Oskar> From a jclass reference I wish to be able to create an instance
Oskar> using a package-private constructor. So I figured I can use
Oskar> _Jv_CallAnyMethodA for this. But I need a jmethodID of the
Oskar> constructor. How do I get that?
I recommend against using _Jv_CallAnyMethodA. This is an ugly
internal function whose name and/or calling convention might change.
Instead you could just use reflection directly. Use
Class.getDeclaredConstructor to get the constructor, and then use
Constructor.newInstance to make a new instance.
This is less efficient than the approaches that rely on internal
knowledge of libgcj, but more likely to continue working. The
efficiency loss comes because this approach does some allocation.
If you really want to use the internals, use JvGetFirstMethod to get
the first jmethodID for your class, and then iterate over the method
ids (looking at the names and signatures) until you find the one you
want. Look in natClass.cc for an example.
Tom