• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Hiding, Shadowing & Obscuring

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain how exactly Hiding, Shadowing & Obscuring are different?
I used to think they are all the same.
TIA
 
Ranch Hand
Posts: 3271
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's lots of good info on this in the JLS, but let me try to explain best I can.
Hiding deals with inheritance of classes. A variable or method in a subclass can hide a variable or method in the superclass. Here's an example:

Shadowing is really the same notion and is, in my opinion, only subtly different. With shadowing, inheritance is not involved. Rather, some variable, which is currently in scope, is "shadowed" by another variable with the same name. This shadowing causes the original variable to be inaccessible (by a simple name) until the new variable goes out of scope. Here's another example:

Obscuring isn't seen very often. Obscuring really occurs when no differentation can be made between the name of a variable, a type, or a package. In general, if you follow proper naming conventions, you'll rarely run into such a case.
Here are some points of interest in the JLS that will give you more info on these three things:
§6.3.1 Shadowing Declarations
§6.3.2 Obscured Declarations
§8.3 Field Declarations
§8.4.6.2 Hiding (by Class Methods)
I hope that helps.
 
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic