Why is there no Constant feature in Java? -
i trying identify reason behind constants in java have learned java allows declare constants using final
keyword.
my question why didn't java introduce constant (const
) feature. since many people has come c++, in c++ have const
keyword.
please share thoughts.
every time go heavy c++ coding java, takes me little while adapt lack of const-correctness in java. usage of const
in c++ different declaring constant variables, if didn't know. essentially, ensures object immutable when accessed through special kind of pointer called const-pointer when in java, in places i'd want return const-pointer, instead return reference interface type containing methods shouldn't have side effects. unfortunately, isn't enforced langauge.
wikipedia offers following information on subject:
interestingly, java language specification regards const reserved keyword — i.e., 1 cannot used variable identifier — assigns no semantics it. thought reservation of keyword occurred allow extension of java language include c++-style const methods , pointer const type. enhancement request ticket in java community process implementing const correctness in java closed in 2005, implying const correctness never find way official java specification.
Comments
Post a Comment