日期:2014-05-20 浏览次数:20782 次
@SuppressWarnings("unused")
public static void main(String[] args) {
List<String> l = new ArrayList<String>(){
private static final long serialVersionUID = -5162194221267685944L;
public List<String> addList(List<String> list ){
this.addAll(new TreeSet<String>(list){
private static final long serialVersionUID = 603932641888586401L;
{
System.out.println(this.getClass());
}
@Override
public Comparator<? super String> comparator() {
return super.comparator();
}
});
return this;
// return Class.forName(this.getClass().toString())this;
}
public List<String> addList1(List<String> list ){
this.addAll(new TreeSet<String>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.compareTo("");
}
}){
private static final long serialVersionUID = -603932641888586401L;
});
return this;
}
{
System.out.println(this.getClass());
}
}.addList(new ArrayList<String>())
// .addList1(new ArrayList<String>())
;
}
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.TreeSet;
public class Main {
@SuppressWarnings("unused")
public static void main(String[] args) {
List<String> l = new ExtraArrayList<String>() {
private static final long serialVersionUID = -5162194221267685944L;
public ExtraArrayList<String> addList(List<String> list) { // Contravariant is used
this.addAll(new TreeSet<String>(list){
private static final long serialVersionUID = 603932641888586401L;
{
System.out.println(this.getClass());
}