Interface Definition in Java 8 and Java 8 Interface Definition
Define an interface. If there is a class to implement this interface, you must implement the methods defined in this interface; if the interface has been written, the class is also written, but if the interface is modified again, a method is added, before Java 8, you must change the interface implementation class. There are two ways to change the class;
1. Add an abstract class. The newly added method www.twitterchina.net in the abstract class interface is used to enable the Implementation class of the original interface to inherit the virtual class.
2. Modify the implementation class of the interface and implement the newly added method in the interface.
Of course, the first method is better, which may have less impact on the project.
You do not need to modify the implementation class of the interface in Java 8.
Public interface Annimal {
Void setType (String type );
String getType ();
// String getAnnimalSex (); // written before Java 8
// Write in Java 8
Default String getAnnimalSex (){
Return "1 ";
};
// Implementation class
Public class Dog implements Annimal {
@ Override
Public void setType (String type ){
// TODO Auto-generated method stub
}
@ Override
Public String getType (){
// TODO Auto-generated method stub
Return null;
}
// @ Override
// Public String getAnnimalSex (){
/// TODO Auto-generated method stub
// Return null;
//}
}
}