char initial value in Java

前端 未结 6 1046
轮回少年
轮回少年 2020-12-08 19:21

You initialize an int variable defined within a method to have a value of 0 until you compute specific values for the int. What can on

6条回答
  •  遥遥无期
    2020-12-08 20:13

    Typically for local variables I initialize them as late as I can. It's rare that I need a "dummy" value. However, if you do, you can use any value you like - it won't make any difference, if you're sure you're going to assign a value before reading it.

    If you want the char equivalent of 0, it's just Unicode 0, which can be written as

    char c = '\0';
    

    That's also the default value for an instance (or static) variable of type char.

提交回复
热议问题