This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes If i want to report a bug Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "If i want to report a bug" Watch "If i want to report a bug" New topic
Author

If i want to report a bug

Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Mhh, I misunderstood the JLS earlier in this thread. The relevant piece actually is this, the second paragraph of 6.6:


Note that accessibility is a static property that can be determined at compile time; it depends only on types and declaration modifiers.


With other words, accessibility is determined by the compile time type of the reference, not by runtime type of the object.

So it's working as specified. And I stand to my point that it needs to work that way to conform to the Liskov Substitution Principle.

Personally, I think the actual design error is that protected methods can be called from outside the inheritance hierarchy at all. Your mileage may vary, of course.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Ilja Preuss:

Personally, I think the actual design error is that protected methods can be called from outside the inheritance hierarchy at all.


Amen to that, brother!


[Jess in Action][AskingGoodQuestions]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
That's how it works in C++, I am told. Probably more sensible. It seems to be how they planned it for Java originally, in this White Paper.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Campbell Ritchie:
That's how it works in C++, I am told. Probably more sensible. It seems to be how they planned it for Java originally, in this White Paper.


Didn't Java 1.0 have a "private protected" modifier that did that? Obviously, that was an even worse idea...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Originally posted by Ilja Preuss:


Didn't Java 1.0 have a "private protected" modifier that did that? Obviously, that was an even worse idea...
Don't know.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Originally posted by Ilja Preuss:
Didn't Java 1.0 have a "private protected" modifier that did that? Obviously, that was an even worse idea...

Yes, but it was removed in the 1.0.2 release (which was the first one to be widely released).


Ping & DNS - my free Android networking tools app
Ganesan Ramakrishnan
Ranch Hand

Joined: Mar 18, 2008
Posts: 88
Hi,

Actually what's happening when assigning the horse object to animal reference. What is the difference bw the reference and object.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
"Ganesan" when you logged in first, you appear to have missed the naming policy which requires first name-space-last name. Please go to "my profile" and correct your displayed name to comply.

CR
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by ganzan Ramakrishnan:
Hi,

Actually what's happening when assigning the horse object to animal reference. What is the difference bw the reference and object.



The only difference is that h is of type Horse, and a is of type Animal. The compiler doesn't even look at the assignments when determining whether you are allowed to call the eat method - in this regard, they are totally irrelevant.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by ganzan Ramakrishnan:
Hi,

Actually what's happening when assigning the horse object to animal reference. What is the difference bw the reference and object.



The only difference is that h is of type Horse, and a is of type Animal. The compiler doesn't even look at the assignments when determining whether you are allowed to call the eat method - in this regard, they are totally irrelevant.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: If i want to report a bug