Forums Register Login

Shadow variables

+Pie Number of slices to send: Send
Hi,

Is shadowing of variables from Super Class in Sub class a good practice?
Is there a situation where it is a must and cannot be avoided?
+Pie Number of slices to send: Send
 

Sharan Ashok Vasandani wrote:Is shadowing of variables from Super Class in Sub class a good practice?


It adds possible ambiguity. I'd prevent it if possible - and as far as I know it's always possible; just rename the variable.

Is there a situation where it is a must and cannot be avoided?


Since there is virtually no limit on the allowed variable names it's almost always possible to avoid it, just by renaming it.
+Pie Number of slices to send: Send
is variable shadowing a best practice or not?
+Pie Number of slices to send: Send
If I say I'd prevent it if possible, does that sound like it's a good thing?
Ever since I found this suit I've felt strange new needs. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1169 times.
Similar Threads
Serailzable Problem....
Garbase Collection
Servlet life : when is it safe to use class var's in servlet
Variables in Java
Thread Safety Question?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:01:24.