“Variable may not have been initialized”

前端 未结 4 555
陌清茗
陌清茗 2020-12-22 02:42

I\'ve got a method that creates a String and another method that changes Strings

void create(){
    String s;
    edit(s);
    System.out.printl         


        
4条回答
  •  时光说笑
    2020-12-22 03:22

    You declare local variable s in method create, so that you need to initialized it before you use it. Remember that java does not have default value for local variable. Init String s = "" or whatever value than your code will run normally.

提交回复
热议问题