Created
March 21, 2015 07:11
-
-
Save aruld/d935bafa7247f3682fe5 to your computer and use it in GitHub Desktop.
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
public interface Api { | |
// constant declarations | |
int CAFEBABE = 0xCAFEBABE; | |
// abstract methods | |
void foo(int data); | |
void bar(int data); | |
// default methods | |
default void foo2(int data) { | |
new Object() { | |
void foo() { | |
validate(data); | |
System.out.println("I am foo v2!"); | |
} | |
}.foo(); | |
} | |
default void bar2(int data) { | |
new Object() { | |
void bar() { | |
validate(data); | |
System.out.println("I am bar v2!"); | |
} | |
}.bar(); | |
} | |
// static methods | |
static String ping() { | |
return "pong!"; | |
} | |
// private methods | |
private boolean validate(int data) { | |
System.out.println("validating input: " + Integer.toHexString(data) + " => " + this); | |
return true; | |
} | |
static void main(String[] args) { | |
Api.ping(); | |
Api api = new Api() { | |
@Override | |
public void foo(int data) { | |
System.out.println("I am legacy foo!"); | |
} | |
@Override | |
public void bar(int data) { | |
System.out.println("I am legacy bar!"); | |
} | |
}; | |
api.foo(CAFEBABE); | |
api.bar(CAFEBABE); | |
api.foo2(CAFEBABE); | |
api.bar2(CAFEBABE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment