properties - If Getter/Setter are replaced at compile time in java; how can their purpose be fulfilled? -


i'm new java. have been reading getter/setter (why use getter/setter , getter/setter poor design). while read on oracle understanding jit. i've 2 questions follows :

my question that, if jit replaces getters/setters actual value while compiling code, how purpose of getter/setter being fulfilled?

how achieve encapsulation ?

if jit replaces getters/setters actual value while compiling code how purpose of getter/setter fulfilled in java particular ?

because it's optimization. getters , setters still work expected - , if later change implementation use different fields or other mechanism, jit compiler have change how transforms code well.

for part, reasoning program design shouldn't care jit compiler @ - that's implementation detail how program happens executed. may want care achieve better performance, doesn't change whether or not program design still holds up.

just because jit may compile code uses getter field directly doesn't mean it's appropriate expose field publicly - expose implementation detail, making hard change later. doesn't matter if change things make jit-compiled code invalid later, because time you're running new code, jit compiler won't aware of did old code anyway.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -