jdk1.8 Interface default method

jdk1.8 version adds some features, as opposed to previous version differences. If not clearly, then, in the course will have a lot of questions.

This method describes the interface particularity interface.

In previous versions of jdk is only allowed in the interface definition method method name, does not allow implementation body.

But in jdk1.8, add a default modifier (note here is not public, protected, default, private four modifiers in default, four modifiers default is not written on behalf of default),

all in jdk1.8 modified method by default, you can write the method body. While achieving class default modified method may not realize, realize once again just when in use

 

interface:

public interface NullAnnotation {

public void getName();


default void getAge(){


}
} 


Implementation class class:
. 1,
NullTest11 class public the implements NullAnnotation { 
@Override public void getName () { } // @Override // public void getAge () { // //} }










2,
public class NullTest11 the implements NullAnnotation {
@Override public void getName () { } @override public void getAge () { } }











Note: in the implementation of that interface when implementing the default method, can use the public modifier modified


Guess you like

Origin www.cnblogs.com/jybky/p/12053255.html