fork download
  1. import java.util.function.Supplier;
  2.  
  3. class Main {
  4. public static void main(String[] args) {
  5. doSomething(Dog::new);
  6. doSomething((Runnable) Dog::new);
  7. Main.<Runnable>doSomething(Dog::new); // Using type witness
  8. }
  9.  
  10. static void doSomething(Runnable r) {
  11. System.out.println("doSomething(Runnable) called");
  12. }
  13.  
  14. static <T> void doSomething(Supplier<T> s) {
  15. System.out.println("doSomething(Supplier) called");
  16. }
  17. }
  18.  
  19. class Dog { }
  20.  
Success #stdin #stdout 0.1s 45956KB
stdin
Standard input is empty
stdout
doSomething(Supplier) called
doSomething(Runnable) called
doSomething(Runnable) called