Reputation: 65
I am trying to cast an interface object:
ScreenController startScreenController = nifty.getScreen("start").getScreenController();
(ScreenController is an interface)
to an object of a class named PrisonStartScreenControl:
startScreenController(PrisonStartScreenControl).setNifty(nifty);
^ but this line causes an error. I know that the startScreenController object is equal to a PrisonStartScreenControl, so how would I be able to cast the interface to its implementor-class?
Upvotes: 1
Views: 74
Reputation: 280
The cast needs to be on the left side of the variable to be cast, not the right, e.g:
((PrisonStartControl)startScreenController).setNifty(nifty);
But, why are you casting anyway? setNifty() should be a method on the interface so no need to cast.
Upvotes: 2