Is final ill-defined?

前端 未结 6 1685
野的像风
野的像风 2021-01-30 02:39

First, a puzzle: What does the following code print?

public class RecursiveStatic {
    public static void main(String[] args) {
        System.out.println(scale         


        
6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 03:21

    Nothing to do with final here.

    Since it is at instance or class level, it holds the default value if nothing gets assigned yet. That is the reason you seeing 0 when you accessing it without assigning.

    If you access X without completely assigning, it holds the default values of long which is 0, hence the results.

提交回复
热议问题