I am having trouble understanding how inheritance works in Java when inner classes are present. I\'m currently working on something where a child class needs to slightly ch
In general, what is the recommended way of altering the behavior of an object's parent class's inner object?
I'd recommend using a less convoluted design to begin with. A child class should modify the behaviour of its parent by overriding its methods, so I'd just add some factory method newInnerClass()
to override the creation of this dependency, and manage this object at the top of the class hierarchy.
This would be more flexible than what you propose, because newInnerClass()
could instantiate a class that's defined wherever as long as it has the right interface.