I need to define a custom RecyclerView and RecyclerView.Adapter. RecyclerView is OK, but I don't know how to define a subclass of RecyclerView.Adapter because of it's Generic type.
This my code, and Android Studio shows Unexpected bound.
public static abstract class Adapter<VH> extends RecyclerView.Adapter<VH extends RecyclerView.ViewHolder>
You should define it like this
public static abstract class Adapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {
}
the structure is like this
class ABC<-definition-> extends DEF<-usage->
It is because the definition has to be done in quote following the class which you are declaring. In the second quote, you only use it.
The meaning of the whole statement is the VH
is definited to be a subclass of RecyclerView.ViewHolder
, and the Adapter<VH>
is a subclass of RecyclerView.Adapter<VH>
. Because VH
has the right superclass, so the whole statement would now be valid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With