The @dll.import directive can also be used prior to the class definition to set a library name for all native methods declared in that class. The following declaration uses @dll.import for an entire class.
/** @dll.import("KERNEL32") */ class EnvironmentStrings { public static native int GetEnvironmentStrings(); public static native int GetEnvironmentVariable(String name, StringBuffer value, int ccbValue); public static native boolean SetEnvironmentVariable(String name, String value); }
It is equivalent to specifying @dll.import for each method, as in the following example.
class EnvironmentStrings { /** @dll.import("KERNEL32") */ public static native int GetEnvironmentStrings(); /** @dll.import("KERNEL32") */ public static native int GetEnvironmentVariable(String name, StringBuffer value, int ccbValue); /** @dll.import("KERNEL32") */ public static native boolean SetEnvironmentVariable(String name, String value); }
Using the @dll.import directive at the class level saves space in the .class file and eliminates redundant information. However, class-level @dll.import directives are not inherited by subclasses.