• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shadow variables

 
Sharan Ashok Vasandani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sharan Ashok Vasandani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is variable shadowing a best practice or not?
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I say I'd prevent it if possible, does that sound like it's a good thing?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic