JAVA default value design reason -


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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -