Advertisement
Guest User

java type inference

a guest
Apr 19th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. interface Foo<T> {
  2.     void doFoo(T arg);
  3. }
  4.  
  5. class Bar<T> {
  6.     private T arg;
  7.     private Foo<T> foo;
  8.  
  9.     Bar(T arg, Foo<T> foo) {
  10.         this.arg = arg;
  11.         this.foo = foo;
  12.     }
  13.  
  14.     void doBar(){
  15.         this.foo.doFoo(this.arg);
  16.     }
  17. }
  18.  
  19. class FooImpl<T> implements Foo<Supplier<T>> {
  20.     public void doFoo(Supplier<T> arg) {
  21.         System.out.println(arg.get());
  22.     }
  23. }
  24.  
  25. public static void main(String... args) {
  26.     new Bar<>(
  27.         "hello, world!",
  28.         new FooImpl<>()
  29.     ).doBar();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement