日期:2014-05-20 浏览次数:20885 次
import java.util.*;
public class Test
{
public static void main(String[] args)
{
List<String> list = new LinkedList<String>();
list.add("abc"); //为什么String,此处不用new也可以,
//为什么下面的parts必须用new?
list.add(new String("abc"));
System.out.println(list);
SortedSet<A> parts = new TreeSet<A>();
// parts.add("abc", 123); //此处如不注释会报错,必须用new形式,
//为什么不能像String一样?
parts.add(new A("abc", 123));
}
}
class A implements Comparable<A>
{
public A(String name, int number)
{
this.name = name;
this.number = number;
}
public String getName()
{
return name;
}
public int getNumber()
{
return number;
}
public int compareTo(A other)
{
return number-other.number;
}
private String name;
private int number;
}