Skip to content

Instantly share code, notes, and snippets.

@sundararajana
Created March 5, 2015 03:59
Show Gist options
  • Save sundararajana/878d1390d2fa3f79c657 to your computer and use it in GitHub Desktop.
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
// 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