Created
July 30, 2015 23:34
-
-
Save shadowfacts/1d9828042b2f1125345a to your computer and use it in GitHub Desktop.
Java 8 Interface Defaults example
This file contains 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
package net.shadowfacts.example; | |
/** | |
* A class that implements Interface1 but only has one custom value. | |
**/ | |
public class Class1 implements Interface1 { | |
public String name() { | |
return "Class1"; | |
} | |
public int method1() { | |
return 1; | |
} | |
public float method2() { | |
return 3.1f; | |
} | |
public boolean method3() { | |
return true; | |
} | |
} |
This file contains 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
package net.shadowfacts.example; | |
/** | |
* A class that implements Interface2 and is only required to implement 1 method because the other 3 have default implementations in Interface2 | |
**/ | |
public class Class2 implements Interface1 { | |
public String name() { | |
return "Class2"; | |
} | |
} |
This file contains 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
package net.shadowfacts.example; | |
/** | |
* An interface | |
**/ | |
public interface Interface1 { | |
String name(); | |
int method1(); | |
float method2(); | |
boolean method3(); | |
} |
This file contains 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
package net.shadowfacts.example; | |
/** | |
* An interface extending Interface1 | |
**/ | |
public interface Interface2 extends Interface1 { | |
default method1() { | |
return 1; | |
} | |
default method2() { | |
return 3.1f; | |
} | |
default method3() { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment