Setter 其中有 class 个实例这可能吗?

Setter which has class instance is this possible?

    private int Li_WtVal;
        List <Integer> ValueList = new ArrayList<Integer>();
        CsReader csReader = new CsReader();    

      public void setLi_WtVal(int li_WtVal) {
                ValueList = csReader.GetAllcsValues();
                li_WtVal = ValueList.get(0);
       }
    public int getLi_WtVal() {
        return Li_WtVal;
    }
}

我在里面有一个 while 循环我正在调用 setter 和 getter 但 evrytime 它 returns 0.

public int CtrlWeight(String CodeLine) {
        Scanner scanner = new Scanner(CodeLine);
        int Li_Wtcs = 0;
        while (scanner.hasNext()) {
            token1 = scanner.next();
            if (token1.contains("if")){
                setLi_WtVal(Li_WtVal);
                Li_Wtcs = Li_Wtcs + getLi_WtVal() ;
            }
        }

setter 可以在其中包含其他 class 个实例和对象引用吗?

你给参数设置的值不是属性:

 public void setLi_WtVal(int li_WtVal) {
            ValueList = csReader.GetAllcsValues();
            Li_WtVal= ValueList.get(0);
   }
public int getLi_WtVal() {
    return Li_WtVal;

我认为原因是因为您对变量的命名很糟糕。

另外看起来你的代码并没有带来多少收益。