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

default methods #134

Closed
goto1134 opened this issue Aug 19, 2017 · 2 comments
Closed

default methods #134

goto1134 opened this issue Aug 19, 2017 · 2 comments

Comments

@goto1134
Copy link
Contributor

goto1134 commented Aug 19, 2017

This issue is about my idea, that, I think, will be very useful.

Native API methods are often designed agains java code conventions (which is normal). A common example is:

int doSomething(ResultType *resultVariable);

where method returns an error code. Java variant of the method whould look like this:

ResultType doSomething() throws LibraryError;

So the default method feature, that appeared in Java 8, can be used to bring some comfort in your code.

interface MyNativeLibrary {
    ErrorCode doSomething(ResultType resultVariable);
    default ResultType doSomething() throws LibraryError
    {
        ResultType resultValue = new ResultType();
        ErrorCode error = doSomething (resultValue);
        if (error != ErrorCode.OK) {
            throw new LibraryError (error);
        }
        return resultValue;
    }
}

To use native interfaces like this, LibraryLoaders should ignore default methods while generating a new stub.
I understand that the library is currently targeted for jdk7+, but I hope, there is a workaround to implement this feature for jdk8+ only.

I'd like to know your opinion about this feature.

@goto1134
Copy link
Contributor Author

goto1134 commented Aug 25, 2017

There is PR #66 about the same feature. But PR #139 shows that test for it was written with an error and was always ignored.

@goto1134
Copy link
Contributor Author

After fixing test in #139 It appeared that default methods are already ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant