Last active
August 29, 2015 13:58
-
-
Save arinto/9994930 to your computer and use it in GitHub Desktop.
Awesome interface with its default method
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
public interface Awesome { | |
/** | |
* say hello! | |
*/ | |
void sayHello(); | |
/** | |
* eat something! | |
* @param something thing to be eaten | |
*/ | |
default void eat(String something) { | |
System.out.printf("nom nom %s.. %n", something); | |
} | |
} |
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
public class AwesomeSingaporean implements Awesome{ | |
@Override | |
public void sayHello() { | |
System.out.println("Hello!"); | |
} | |
@Override | |
public void eat(String something) { | |
System.out.printf("makan %s..%n", something); | |
} | |
} |
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
public class InterfaceEvolutionMain { | |
public static void main(String[] args) { | |
List<Awesome> awesomePeople = new LinkedList<>(); | |
Awesome spaniard = new AwesomeSpaniard(); | |
awesomePeople.add(spaniard); | |
Awesome indonesian = new AwesomeIndonesian(); | |
awesomePeople.add(indonesian); | |
Awesome swedish = new AwesomeSwedish(); | |
awesomePeople.add(swedish); | |
Awesome singaporean = new AwesomeSingaporean(); | |
awesomePeople.add(singaporean); | |
awesomePeople.forEach(ap -> { | |
ap.sayHello(); | |
ap.eat("roti prata kosong"); | |
}); | |
} | |
} |
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
Hola! | |
nom nom roti prata kosong.. | |
Halo! | |
nom nom roti prata kosong.. | |
Hej hej! | |
nom nom roti prata kosong.. | |
Hello! | |
makan roti prata kosong.. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment