Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created July 31, 2011 16:10
Show Gist options
  • Save kmizu/1116918 to your computer and use it in GitHub Desktop.
Save kmizu/1116918 to your computer and use it in GitHub Desktop.
By using diamond operator, type inference is done correctly.
import java.util.*;
public class DiamondOperators {
public static void main(String[] args) {
Collection<? extends Number> collection = null;
List<? super String> list = new ArrayList<>(collection);
}
}
@kmizu
Copy link
Author

kmizu commented Jul 31, 2011

mizushima@ubuntu:~$ javac DiamondOperators.java
DiamondOperators.java:5: error: incompatible types
    List<? super String> list = new ArrayList<>(collection);
                                ^
  required: List<? super String>
  found:    ArrayList<Number>
1 error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment