Home > Back-end >  Is it possible to implement native methods in interfaces?
Is it possible to implement native methods in interfaces?

Time:09-28

You often hear that methods in an interface have no implementation. However, in Java 8 it became possible to implement the default methods. But I'm interested. Was and is it possible to implement interface methods natively? (native methods).

When the interview question is asked - "Is it possible to implement a method in an interface?" Answer - you can make a native method implementation, and since Java 8 it is possible to define a default method." How correct is this answer?

CodePudding user response:

No, interfaces can't have native methods:

Note that an interface method may not be declared [..] with the modifiers final, synchronized, or native.

Technically that text is non-normative, because it only points out that this list does not contain the mentioned modifiers:

InterfaceMethodModifier:
    (one of)
    Annotation public private
    abstract default static strictfp

  • Related