• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is right syntax to bypass virtual method call?  RSS feed

 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have class A, like


Now I want to call method from some parrent, like:

However I'm getting foo() called from B.
I tried some modifiers like:

However is not right syntax. I can use reflection for that, or define something like:

However it doesn't look right either. Please help.
 
bart zagers
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to achieve?
The behaviour you get is exactly what it is supposed to do. You override the base class method with a more specific implementation in the subclass. If you need both, you should not override the method in the first place, but choose another name for it.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. I made my day. The problem is that I can control overrriding in my classes, but when I use a library, I can't change its implementation so easily, however I may have intention to call parent methods.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java language does not provide a way to do what you want, by design. If a class overrides an inherited method, the inherited method is inaccessible to all other classes.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, it's what I'd like to hear. So I'll stick with backdoor as reflection.
 
Bert Bates
author
Sheriff
Posts: 8954
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
intermediate forum bound
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!