fork(3) download
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Collection;
  4. import java.util.List;
  5.  
  6. interface Callback<T> {
  7. void call(T t);
  8. }
  9.  
  10. class ConcreteCallback implements Callback<Collection<Object>> {
  11. public void call(final Collection<Object> data) {
  12. for (Object obj: data) {
  13. System.out.println(obj);
  14. }
  15. }
  16. }
  17.  
  18. public class Main {
  19. private static <T> void call(final List<T> data, final Callback<? super List<? super T>> cb) {
  20. ArrayList<T> dat = new ArrayList<>();
  21. for (T object: data) {
  22. dat.add(object);
  23. }
  24. cb.call(dat);
  25. }
  26.  
  27. public static void main(final String... args) {
  28. call(Arrays.asList(args), new ConcreteCallback());
  29. }
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:28: error: method call in class Main cannot be applied to given types;
        call(Arrays.asList(args), new ConcreteCallback());
        ^
  required: List<T>,Callback<? super List<? super T>>
  found: List<String>,ConcreteCallback
  reason: no instance(s) of type variable(s) T exist so that argument type ConcreteCallback conforms to formal parameter type Callback<? super List<? super T>>
  where T is a type-variable:
    T extends Object declared in method <T>call(List<T>,Callback<? super List<? super T>>)
1 error
stdout
Standard output is empty