问题
I am creating a generic, abstract class like this:
abstract class BaseDialogFragment<T: Parcelable> : DialogFragment()
Trying to implement this class as
class MyDialogFragment : BaseDialogFragment<String>()
gives me
Type argument is not within its bounds Expected: Parcelable Found: String
for the String in BaseDialogFragment<String>()
.
So, how can I use String
as a value for T
? Is my condition T: Parcelable
somehow wrong, if I want T
to be a parcelable type?
回答1:
So, how can I use String as a value for T?
You can't. String
is not Parcelable
, because Parcel
already knows how to handle String
. Similarly, you cannot use ByteArray
for T
, or Int
, or Boolean
.
来源:https://stackoverflow.com/questions/61462507/type-argument-is-not-within-its-bounds-expected-parcelable-found-string