• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If i want to report a bug

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49864
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49864
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ganesan Ramakrishnan
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49864
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic