On Jun 27, 2007, at 1:34 AM, Wayne Meissner wrote:
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.
One argument for allowing Pointer-derived types is that you could use
MyPointer any place you'd normally use Pointer, and have the JNA
library automatically handle the mapping (avoids the user having to
define one or more custom mappings for the type).
The library already does this sort of auto-mapping with structures;
if a return type is derived from Structure, the derived type is
instantiated on the fly.
The type mapping is not overly onerous, but if it winds up being a
bunch of boilerplate, the library should probably handle the pattern
automatically.