Type mismatch: inferred type is kotlin.collections.ArrayList<WorkerUser> /* = java.util.ArrayList<WorkerUser> but kotlin.collections.ArrayList<RecyclerViewAdapter.ListItem> java.util.ArrayList<RecyclerViewAdapter.ListItem> was expected


#1

Type mismatch: inferred type is kotlin.collections.ArrayList /* = java.util.ArrayList / but kotlin.collections.ArrayList<RecyclerViewAdapter.ListItem> / = java.util.ArrayList<RecyclerViewAdapter.ListItem> */ was expected

my WorkerUser class is implementing RecyclerViewAdapter.ListItem interface

in Java it works, but why this is not working here?


#2

You have a covariance issue. A list of WorkerUser is not a valid list of ListItem as it is possible to take a list of ListItem, add an element that is a ListItem but not WorkerUser. You probably wanted to use the readOnly List interface which does not have this issue on the receiver.