Skip to content

Instantly share code, notes, and snippets.

@watermint
Created July 26, 2013 02:20
Show Gist options
  • Save watermint/6085556 to your computer and use it in GitHub Desktop.
Save watermint/6085556 to your computer and use it in GitHub Desktop.
enumにデフォルト実装をもたせられるか
interface Animal {
default void say() {
System.out.println("I'm Animal");
}
}
enum Bird implements Animal {
Sparrow,
Pigeon
}
public class A {
public static void main(String... args) {
Bird.Sparrow.say();
}
}
% /usr/libexec/java_home -v 1.8 -exec javac A.java
% /usr/libexec/java_home -v 1.8 -exec java A
I'm Animal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment