Skip to content

Instantly share code, notes, and snippets.

@arinto

arinto/Awesome.java

Last active Aug 29, 2015
Embed
What would you like to do?
Awesome interface with its default method
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);
}
}
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);
}
}
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");
});
}
}
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
You can’t perform that action at this time.