首页 > 其他 > 详细

静态类

时间:2015-06-07 12:27:47      阅读:212      评论:0      收藏:0      [点我收藏+]

今天写了一个例子。

public static void main(String[] args){
SortedSet<Person> set = new TreeSet<Person>();
set.add(new Person(180));
set.add(new Person(175));

for(Person p : set){
System.out.println("身高: " + p.getHeight());
}
}

 

然后在同样文件里面定义

class Person implements Comparable<Person>{
    private int height;
    public Person(int _age){
        height = _age;
    }
    public int getHeight(){
        return this.height;
    }
    
    public void setHeight(int height){
        this.height = height;
    }
    @Override
    public int compareTo(Person o){
        return height - o.height;
    }

这个时候 编译器会报错:

No enclosing instance of type listSort is accessible. Must qualify the allocation with an enclosing instance of type listSort (e.g. x.new A() where x is an instance of listSort).

但是如果我把person类单独拿出来作为一个class,这个时候就不会报错。

具体原因我想是编译器编译顺序的问题。后面可以在查查资料看看具体原因。

静态类

原文:http://www.cnblogs.com/edenpans/p/4558179.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!