Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Class<T> to Class<T extends Library> for Native.loadLibrary #861

Merged
merged 1 commit into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/com/sun/jna/Native.java
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public static List<String> toStringList(char[] buf, int offset, int len) {
* @throws UnsatisfiedLinkError if the library cannot be found or
* dependent libraries are missing.
*/
public static <T> T loadLibrary(Class<T> interfaceClass) {
public static <T extends Library> T loadLibrary(Class<T> interfaceClass) {
return loadLibrary(null, interfaceClass);
}

Expand All @@ -522,7 +522,7 @@ public static <T> T loadLibrary(Class<T> interfaceClass) {
* dependent libraries are missing.
* @see #loadLibrary(String, Class, Map)
*/
public static <T> T loadLibrary(Class<T> interfaceClass, Map<String, ?> options) {
public static <T extends Library> T loadLibrary(Class<T> interfaceClass, Map<String, ?> options) {
return loadLibrary(null, interfaceClass, options);
}

Expand All @@ -540,7 +540,7 @@ public static <T> T loadLibrary(Class<T> interfaceClass, Map<String, ?> options)
* dependent libraries are missing.
* @see #loadLibrary(String, Class, Map)
*/
public static <T> T loadLibrary(String name, Class<T> interfaceClass) {
public static <T extends Library> T loadLibrary(String name, Class<T> interfaceClass) {
return loadLibrary(name, interfaceClass, Collections.<String, Object>emptyMap());
}

Expand All @@ -560,8 +560,9 @@ public static <T> T loadLibrary(String name, Class<T> interfaceClass) {
* @throws UnsatisfiedLinkError if the library cannot be found or
* dependent libraries are missing.
*/
public static <T> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
public static <T extends Library> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) {
if (!Library.class.isAssignableFrom(interfaceClass)) {
// Maybe still possible if the caller is not using generics?
throw new IllegalArgumentException("Interface (" + interfaceClass.getSimpleName() + ")"
+ " of library=" + name + " does not extend " + Library.class.getSimpleName());
}
Expand Down
2 changes: 1 addition & 1 deletion test/com/sun/jna/NativeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testLoadLibraryMethods() throws Exception {
Method m = Native.class.getMethod("loadLibrary", paramTypes);
Class<?> returnType = m.getReturnType();
signature.append(Native.getSignature(returnType));
assertSame("Mismatched return type for signature=" + signature, Object.class, returnType);
assertSame("Mismatched return type for signature=" + signature, Library.class, returnType);
// System.out.println("===>" + m.getName() + ": " + signature);
} catch(NoSuchMethodError err) {
fail("No method for signature=" + signature);
Expand Down