fork download
  1. @FunctionalInterface
  2. interface ShiaLabeouf{
  3. void justDoIt();
  4. }
  5. class DoA implements ShiaLabeouf{
  6. public void justDoIt(){
  7. System.out.println("Yesterday you said tomorrow !");
  8. }
  9. }
  10.  
  11. abstract class ClassUser {
  12. private ShiaLabeouf s;
  13. public ClassUser(ShiaLabeouf s){
  14. this.s = s;
  15. }
  16. public void doIt(){
  17. s.justDoIt();
  18. }
  19. }
  20.  
  21. class Test {
  22. public static void main(String[] args){
  23. ClassUser cu1 = new ClassUser(new DoA()){
  24. // D'autres trucs ici
  25. };
  26.  
  27. ClassUser cu2 = new ClassUser(new ShiaLabeouf(){
  28. @Override
  29. public void justDoIt(){
  30. System.out.println("Nothing is impossible");
  31. }
  32. }){
  33. // D'autres trucs ici
  34. };
  35.  
  36. ClassUser cu3 = new ClassUser(() -> {
  37. System.out.println("Make your dreams come true");
  38. }){
  39. // D'autres trucs ici
  40. };
  41.  
  42. cu1.doIt();
  43. cu2.doIt();
  44. cu3.doIt();
  45. }
  46. }
Success #stdin #stdout 0.19s 320704KB
stdin
Standard input is empty
stdout
Yesterday you said tomorrow !
Nothing is impossible
Make your dreams come true