I have:
class BaseActivity extends Activity { ... }
and i want to change it like this:
class BaseActivity<T extends BaseActivity<T>> { ... }
but i dont want to change all files in project
and in Java i can do:
class HomeActivity extends BaseActivity { ... }
yes i will get "Raw use of parameterized class 'BaseActivity'" warning but in kotlin i have to explicitly write a type:
class HomeActivity : BaseActivity<HomeActivity>() { ... }
or error will be "One type argument expected for class BaseActivity<T : BaseActivity<*>!>"
is there any option to make it work?
This trick is to allow the superclass to use the type of subclass.
For example, you could define fields/methods in
BaseActivity<T>asthen in your subclass
HomeActivitywhich extends fromBaseActivity<HomeActivity>will have typed members from the superclass,Using raw type causes the loss of types of these members.