Create Object in if-statement and use it later

前端 未结 3 1805
[愿得一人]
[愿得一人] 2021-01-26 09:41

I am writing a Parser for Infix Notation. In the if-statement I declare the variable newchild. Otherwise I want it to throw an exception. But when I am out of the scope the Comp

3条回答
  •  不思量自难忘°
    2021-01-26 10:05

    you can do:

    int value = = -1;
    Leaf res = null;
    if(Character.isDigit(tokenList.get(i).charAt(1))){
          value =Integer.parseInt(tokenList.get(i));                
          res = new Leaf(value);
     }
    

    and check out of the if what values are stored in the variables value and res

提交回复
热议问题