fork download
  1. import java.util.*;
  2.  
  3. class Example {
  4. public static void main(String[] args) {}
  5.  
  6. private void addString(List<? extends String> list, String s) {
  7. list.add(s); // does not compile
  8. list.add(list.get(0)); // doesn't compile either
  9. }
  10. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:7: error: no suitable method found for add(String)
	    list.add(s); // does not compile
	        ^
    method Collection.add(CAP#1) is not applicable
      (argument mismatch; String cannot be converted to CAP#1)
    method List.add(CAP#1) is not applicable
      (argument mismatch; String cannot be converted to CAP#1)
  where CAP#1 is a fresh type-variable:
    CAP#1 extends String from capture of ? extends String
Main.java:8: error: no suitable method found for add(CAP#1)
	    list.add(list.get(0)); // doesn't compile either
	        ^
    method Collection.add(CAP#2) is not applicable
      (argument mismatch; String cannot be converted to CAP#2)
    method List.add(CAP#2) is not applicable
      (argument mismatch; String cannot be converted to CAP#2)
  where CAP#1,CAP#2 are fresh type-variables:
    CAP#1 extends String from capture of ? extends String
    CAP#2 extends String from capture of ? extends String
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
2 errors
stdout
Standard output is empty