-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Structure.newInstance should be generified so cast isn't necessary #889
Comments
The signature was: `Structure newInstance(Class<?> type)` requiring an explicit cast after the call. The the new signature introduces a type parameter `T` with an upper bound of `com.sun.jna.Structure`: <T extends Structure> T newInstance(Class<T> type)` The companion, that takes an init pointer was also updated: <T extends Structure> T newInstance(Class<T> type, Pointer init) Closes: java-native-access#889
The signature was: `Structure newInstance(Class<?> type)` requiring an explicit cast after the call. The the new signature introduces a type parameter `T` with an upper bound of `com.sun.jna.Structure`: <T extends Structure> T newInstance(Class<T> type)` The companion, that takes an init pointer was also updated: <T extends Structure> T newInstance(Class<T> type, Pointer init) Closes: java-native-access#889
Please have a look at #898. I'd like to have a few more opinions on this before it is merged. As the change is binary-incompatible it can only go into the master branch and won't be backported into 4.5.1-dev. |
Thanks. I thought the whole deal was that the source was not compatible but that the binary generated was in some sense or the other, I could be mistaken about that though. This post at https://stackoverflow.com/questions/2721546/why-dont-java-generics-support-primitive-types seems to agree with the backwards compatible idea though. The code looks good although I think the refactoring should be done so that going from without a cast to a cast in the diff to |
The signature was: `Structure newInstance(Class<?> type)` requiring an explicit cast after the call. The the new signature introduces a type parameter `T` with an upper bound of `com.sun.jna.Structure`: <T extends Structure> T newInstance(Class<T> type)` The companion, that takes an init pointer was also updated: <T extends Structure> T newInstance(Class<T> type, Pointer init) Closes: java-native-access#889
You are right for For your comment about "refactoring": I'd really get the casts down. Could you suggest code changes? |
Sure thing, let me get the code checked out.. give me a little bit |
I haven't had time to check the code out yet, but what you can do, if you are running Eclipse, which I highly recommend if not, is to right-click on the newInstance method and click on the References dropdown/context menu, then click Workspace. Basically, just let the compiler guide you thru the source tree |
Eclipse does not more than any other IDE at this point. In netbeans it is called "Find usages", but that does not solve the "cast problem" and I assume IDEA et al. offer the same. |
@crowlogic I pulled in the PR, feel free to suggest optimization for the internal casts. |
the cast shouldn't be necessary, the method definition should be
public static <T extends Structure> T newInstance(Class<T> type, Pointer init) throws IllegalArgumentException { ... }
The text was updated successfully, but these errors were encountered: