Skip to content

default methods #134

@goto1134

Description

@goto1134

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions