fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<? super Number> test = new ArrayList<Object>();
  13. test.add(new Double(1.2));
  14. test.add(new Integer(1));
  15. test.add(new Float(2.3));
  16. test.add(new Object());
  17. if(test.get(0) instanceof Integer){
  18. System.out.println("Integer");
  19. } else if(test.get(0) instanceof Double){
  20. System.out.println("Double");
  21. }
  22. }
  23. }
Compilation error #stdin compilation error #stdout 0.07s 2841600KB
stdin
Standard input is empty
compilation info
Main.java:16: error: no suitable method found for add(Object)
        test.add(new Object());
            ^
    method Collection.add(CAP#1) is not applicable
      (argument mismatch; Object cannot be converted to CAP#1)
    method List.add(CAP#1) is not applicable
      (argument mismatch; Object cannot be converted to CAP#1)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends Object super: Number from capture of ? super Number
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
stdout
Standard output is empty