@FunctionalInterface
interface ShiaLabeouf{
void justDoIt();
}
class DoA implements ShiaLabeouf{
public void justDoIt(){
System.
out.
println("Yesterday you said tomorrow !"); }
}
abstract class ClassUser {
private ShiaLabeouf s;
public ClassUser(ShiaLabeouf s){
this.s = s;
}
public void doIt(){
s.justDoIt();
}
}
class Test {
public static void main
(String[] args
){ ClassUser cu1 = new ClassUser(new DoA()){
// D'autres trucs ici
};
ClassUser cu2 = new ClassUser(new ShiaLabeouf(){
@Override
public void justDoIt(){
System.
out.
println("Nothing is impossible"); }
}){
// D'autres trucs ici
};
ClassUser cu3 = new ClassUser(() -> {
System.
out.
println("Make your dreams come true"); }){
// D'autres trucs ici
};
cu1.doIt();
cu2.doIt();
cu3.doIt();
}
}
QEZ1bmN0aW9uYWxJbnRlcmZhY2UKaW50ZXJmYWNlIFNoaWFMYWJlb3VmewogICAgdm9pZCBqdXN0RG9JdCgpOwp9CmNsYXNzIERvQSBpbXBsZW1lbnRzIFNoaWFMYWJlb3VmewogICAgcHVibGljIHZvaWQganVzdERvSXQoKXsKICAgIAlTeXN0ZW0ub3V0LnByaW50bG4oIlllc3RlcmRheSB5b3Ugc2FpZCB0b21vcnJvdyAhIik7CiAgICB9Cn0KCmFic3RyYWN0IGNsYXNzIENsYXNzVXNlciB7CiAgICBwcml2YXRlIFNoaWFMYWJlb3VmIHM7CiAgICBwdWJsaWMgQ2xhc3NVc2VyKFNoaWFMYWJlb3VmIHMpewogICAgICAgIHRoaXMucyA9IHM7CiAgICB9CiAgICBwdWJsaWMgdm9pZCBkb0l0KCl7CiAgICAgICAgcy5qdXN0RG9JdCgpOwogICAgfQp9CgpjbGFzcyBUZXN0IHsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpewoJCUNsYXNzVXNlciBjdTEgPSBuZXcgQ2xhc3NVc2VyKG5ldyBEb0EoKSl7CgkJICAgIC8vIEQnYXV0cmVzIHRydWNzIGljaQoJCX07CgkJCgkJQ2xhc3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