类型ArrayList <bar>的方法change(Bar,Bar)未定义

时间:2019-03-18 14:49:50

标签: java arraylist

我试图更改'Bar'对象的值,我创建了一个采用2个bar变量的change方法,但是当我尝试在compareBar方法中的'list.get(i)'上使用它时我收到一个错误消息,指出该方法对于ArrayList类型是未定义的,这不是Bar对象吗?如何更改它以便如此?

 public class Envelope {
    ArrayList<Bar> list = new ArrayList<Bar>();


    //Compares and adjusts range of bars accordingly    
    public void compareBars() {
        for(int i = 0; i < list.size(); i++) {
            if(list.get(i+1).left <= list.get(i).right) {
                if(list.get(i).height >= list.get(i+1).height) {
                    list.change(list.get(i+1),list.get(i));
                }else if(list.get(i+1).height >= list.get(i).height) {
                    list.change(list.get(i),list.get(i+1));
                }
            }
        }
    }
    // Modifies ranges of bar values
    public void change(Bar target, Bar replacement) {
        if(target.left < replacement.left) {
            target.right = replacement.left;            
        }
        if (target.left > replacement.left) {
            target.left = replacement.right;
        }
    }

}

0 个答案:

没有答案