Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 11
    With reflection you can do anything, yes :) You can even make strings mutable. Commented May 7, 2010 at 14:30
  • 27
    What a horrible thing to do! I'm giving you +1 just for figuring out how to do it at all :) Commented May 18, 2010 at 14:06
  • 6
    It's a nice trick but even that is not always equivalent to calling the unavilable, yet needed) super.super and that is because the super.super call would carry the context of C (C+B+A) whereas your answers creates an instance of A without the context of B and C. So this answer will not work if every doThat called getContext(), for example, and getContext was implemented differently in each class. in your answer it would use A's getContext() whereas calling the unavailable super.super would have resulted in using C's getContext. Commented Nov 15, 2012 at 9:55
  • Hmm. In some cases, perhaps you could overcome inor's objection with dynamic proxies (javahowto.blogspot.co.uk/2011/12/…), redirecting method calls to the original object (synchronizing variables after each call)? It seems that proxies require everything to be implementing an interface, though. Also, I wonder if it's possible for the super-super class to call one of its super-super methods, specifically, and you'd need NOT to redirect those.... Commented Jul 3, 2014 at 3:42
  • 1
    I said in another comment that blocking super.super. invites programmers to find new, convoluted and egregious ways to shoot themselves in the foot in the pursuit of a workaround, this is a perfect example of that, because your colleagues will probably hate you so much for writing something like this that they will personally and literally shoot you in the foot. +1 Commented Mar 18, 2019 at 21:55