fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static List<? extends Object> produce(){
  8. return null; // Whatever
  9. }
  10.  
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. }
  14.  
  15. public static void a(NoGeneric noGeneric){
  16. noGeneric.call(produce());
  17. }
  18.  
  19. public static <T> void b(Generic<T> generic){
  20. generic.call(produce());
  21. }
  22.  
  23. public static <T, U extends Generic<T>> void d(U generic){
  24. generic.call(produce());
  25. }
  26.  
  27. public static <T extends Generic> void c(T raw){
  28. raw.call(produce());
  29. }
  30. }
  31.  
  32. class NoGeneric{
  33. public void call(List<Object> objects){ }
  34. }
  35.  
  36. class Generic<T> {
  37. public void call(List<Object> objects){}
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:16: error: incompatible types: List<CAP#1> cannot be converted to List<Object>
		noGeneric.call(produce());
		                      ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ? extends Object
Main.java:20: error: incompatible types: List<CAP#1> cannot be converted to List<Object>
		generic.call(produce());
		                    ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ? extends Object
Main.java:24: error: incompatible types: List<CAP#1> cannot be converted to List<Object>
		generic.call(produce());
		                    ^
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object from capture of ? extends Object
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
3 errors
stdout
Standard output is empty