Override property types in child classes in java android -
i'm trying implement app mvp (model-view-presenter) pattern in android i'm facing problem. want have abstract base presenter view class property of generic type viewinterface
when creating real presenter i'd property of type realpresenterview
, if possible without needing override same function in presenters.
as didn't explain myself here's bit of code illustrate case, first base presenter:
abstract public class basepresenter { protected viewinterface view; protected viewinterface getview() { return view; } }
then real presenter
public class realpresenter { protected realpresenterview view; // ... view.methodonlyexistinginrealpresenterview(); }
i wanted able use view in realpresenter realpresenterview without needing add code in class. possible?
i've read class templates haven't seen how implement in case without adding functions in every presenter.
you can use generics :
basepresenter
abstract public class basepresenter<t extends viewinterface> { protected t view; protected t getview() { return view; } }
realpresenter
public class realpresenter extends basepresenter<realpresenterview> { }
note didn't code in java time, think that's ok.
Comments
Post a Comment