Created
March 5, 2015 03:59
-
-
Save sundararajana/878d1390d2fa3f79c657 to your computer and use it in GitHub Desktop.
default and static methods in interfaces #java8 and private interface methods in #java9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jdk8 allows default methods and static methods in interfaces | |
// see also http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html | |
// jdk9 allows private methods in interfaces | |
// see also http://mail.openjdk.java.net/pipermail/core-libs-dev/2015-March/032055.html | |
import java.util.concurrent.Callable; | |
public interface MyRunnable extends Runnable, Callable { | |
default public void run() { | |
func(); | |
} | |
default Object call() { | |
func(); | |
return null; | |
} | |
private void func() { | |
System.out.println("hello"); | |
} | |
public static void main(String[] args) throws Exception { | |
(new MyRunnable() {}).run(); | |
(new MyRunnable() {}).call(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment