Reputation: 936
So my problem is simple, In java if i have a base class like this:
BaseViewModel.Java
public abstract class BaseViewModel<N> extends ViewModel {
I can extend this class to other classes without defining the generic argument N, like this:
public class BaseFragment<V extends BaseViewModel> { //this is fine
but kotlin throws an error with this approach asking for the generic definition.
class BaseFragment<V: BaseViewModel>: Fragment() {// one type argument expected
how to avoid this?
Upvotes: 0
Views: 1103
Reputation: 10106
Kotlin doesn't allow to use raw types as Java does. Thus, you have to specify some type for your V : BaseViewModel
:
class BaseFragment<V: BaseViewModel<Any>>: Fragment() {
It is equivalent for your Java code cause V extends BaseViewModel
basically means V extends BaseViewModel<Object>
Upvotes: 3