I have found in Java Tutorials here this sample code:
public interface Flyer {
default public String identifyMyself() { //<- the default modifier gives an error
return "I am able to fly.";
}
}
I tried to compile it but as I stated it eclipse gives me an error: Syntax error on token "default", delete this token
.
My question is why I cannot run the above code? In fact I cannot run the whole example. Was the default
modifier for interface methods introduced after some Java version (I am using 1.6 I think)?
Java default method in interface is new feature in java 8 :
Check Out http://java.dzone.com/articles/interface-default-methods-java
Java 8中引入了默认方法,因此它们在Java 6中将不起作用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.