FULL PRODUCT VERSION :
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin iMac-Marcin 17.3.0 Darwin Kernel Version 17.3.0: Thu Nov 9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
Returned generic type which is declared from inner public classes loses original type.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I provided code below
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Error:(7, 55) java: cannot find symbol
symbol: method getActionButtonEvent()
location: class com.marurban.BaseViewModel<com.marurban.FavoriteLeaguesViewModel.Accessor,com.marurban.FavoriteLeaguesViewModel.ViewEvents,com.marurban.FavoriteLeaguesViewModel.FlowEvents>.FlowEvents
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Main {
public static void main(String[] args) {
new FavoriteLeaguesViewModel().getFlowEvents().getActionButtonEvent();
}
}
public abstract class BaseViewModel<FlowEvents extends BaseViewModel.FlowEvents> {
private FlowEvents flowEvents;
public BaseViewModel() {
flowEvents = createFlow();
}
protected abstract FlowEvents createFlow();
public FlowEvents getFlowEvents() {
return flowEvents;
}
public class FlowEvents {
}
}
public abstract class FavoritesViewModel<FlowEvents extends FavoritesViewModel.FlowEvents>
extends BaseViewModel<FlowEvents> {
List list;
public FavoritesViewModel() {
super();
}
public abstract class FlowEvents extends BaseViewModel.FlowEvents {
public List getActionButtonEvent() {
return list;
}
}
}
public class FavoriteLeaguesViewModel extends FavoritesViewModel<FavoriteLeaguesViewModel.FlowEvents> {
public FavoriteLeaguesViewModel() {
super();
}
@Override
protected FlowEvents createFlow() {
return new FlowEvents();
}
public class FlowEvents extends FavoritesViewModel.FlowEvents {
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You need to explicitly cast to proper class.
public class Main {
public static void main(String[] args) {
FavoriteLeaguesViewModel viewModel = new FavoriteLeaguesViewModel();
FavoriteLeaguesViewModel.FlowEvents flowEvents = (FavoriteLeaguesViewModel.FlowEvents) viewModel.getFlowEvents();
flowEvents.getActionButtonEvent();
}
}