This is the mail archive of the java-discuss@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: invoking package-private constructor from native code


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]