JAVA default value design reason -
this question has answer here:
in java world, field variables have default values if don't initialize them, while local variables don't.
i have considered lot , searched lot still don't understand. why java world design that? way, think has heap , stack.
local variables easier check variable initialised in relatively limited scope when can determine code paths. doesn't right job unless code confusing.
final
fields have initialised, though once. when 1 constructor calls another, can confused.
for non final fields, hard ensure field initialised before used possible code paths. e.g. how can ensure setter
called before getter
if calls made class might changed in future.
instead jvm leaves default values , makes problem worry about.
Comments
Post a Comment