Ben Chase wrote:
So, given the above, at point of use, as soon as I get a Pointer (from
PointerByReference.getVal()), I need to convert it to an ImageHandle
using the above ctor. Not as elegant as what Wayne wrote, I guess.
(Uh, I confess that I'm still trying to figure out exactly what Wayne
wrote.)
Without delving into the internal workings of JNA, what the argument
converters do behind the scenes, is convert:
Media.INSTANCE.readImage(img);
into:
Media.INSTANCE.readImage(img.handle);
Assuming img looks like:
class ImageHandle {
Pointer handle;
}
This way, you get the added type safety of specific java classes
(instead of using Pointer everywhere) without having to extend Pointer
(and having to work-around package-private constructors like you did).
Unless you really need/want users to be able to access the Pointer
methods (like readInt, writeInt, etc), I recommend delegation over
inheritance when wrapping a C/C++ api like that.
It makes for a cleaner API, and doesn't clutter up
code-completion/intellisense with a bazillion methods you don't need.