• 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

Calling Superclass version of an Overridden Method

 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My method is passed an object whose type is not known until runtime. I know it must be a subclass of a system class e.g. java.awt.Component. I want to execute the standard API version of its method e.g. Component.getLocation() rather than some overridden version implemented by the object itself. Should I do this with reflection API? Are there any other alternatives?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How will you do it using reflection
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From within the subclass itself, you can do this with super:

But from the "outside", there's no easy way to do that, other than reflection.

But why do you need to do this? It sounds like there might be something wrong with the design or architecture of your application if you feel you need to do this - do you not trust what the getLocation() method of the subclass does, or does the getLocation() method of the subclass do something else than it's supposed to do?
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some legacy code have changed the sematic of Component.getLocation() into relative to the Applet rather than the parent. Now I am writing a system monitoring/debugging tool for my appli. and I want to know the location using the original getLocation() semantic. I don't want to touch any existing code/recompile anything. It would be a big deal I don't want to get involved.

So, this can be done by reflection?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alec Lee wrote:So, this can be done by reflection?


Yes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic