Why is there no Constant feature in Java?

后端 未结 8 1837
青春惊慌失措
青春惊慌失措 2020-11-28 02:20

I was trying to identify the reason behind constants in Java I have learned that Java allows us to declare constants by using final keyword.

My question

8条回答
  •  北海茫月
    2020-11-28 03:18

    The C++ semantics of const are very different from Java final. If the designers had used const it would have been unnecessarily confusing.

    The fact that const is a reserved word suggests that the designers had ideas for implementing const, but they have since decided against it; see this closed bug. The stated reasons include that adding support for C++ style const would cause compatibility problems.

提交回复
热议问题