Setter which has class instance is this possible?

Dinu_Girl :
    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;
    }
}

And I have a while loop inside it I'm calling the setter and getter but evrytime It 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() ;
            }
        }

Can setter has other class instances and object ref inside it?

Jens :

You set the value to the parameter not to the property:

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

I think the reason is because your teriable naming of the variables.

Also Looks like your code doesn't make much.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=318013&siteId=1