У меня есть следующие классы в Java
class A which is inherited by class A1 and A2
A has method run and both A1, A2 are overriding this method
Another model class B
B has JSON subtypes B1 and B2 (child classes)
То, чего я хочу достичь сейчас, - это запустить
InstanceOfA.run(B) where B is a reference to B1 subtype, it should execute A1's run method
and If I run InstanceOfA.run(B) where B is a reference to B2 subtype, It should execute A2's run method.
InstanceOfA - это экземпляр A.
Если это возможно, я могу ввести A, используя аннотацию @Inject во всех других классах (где это требуется), и мне не нужно передавать фактические реализации.
Любое другое решение также приветствуется.