日期:2014-05-20 浏览次数:20875 次
public Class User implements Comparable
{
private String username;
public int compareTo(Object obj)
{
User o = (User)obj;
return username.compareTo(o.getUsername());
}
public String getUsername()
{
return username;
}
}
public Class User implements Comparable<User>
{
private String username;
public int compareTo(User o)
{
return username.compareTo(o.getUsername());
}
public String getUsername()
{
return username;
}
}
public class User implements Comparable<User> {
private String username;
public User(String a){
username = a;
}
@Override
public int compareTo(User o) {
return username.compareTo(o.getUsername());
}
public String getUsername() {
return username;
}
}
public class UserTest {
public static void main(String[] args)
{
User a = new User("Zhang fei");
User b = new User("Liu Bei");
int c = a.compareTo(b);
}
}
Hi,楼主这段代码报这个错误:Syntax error on token "Class", class expected
Class 应该改成 class