Search code examples
androidgenericskotlinparcelable

Type argument is not within its bounds Expected: Parcelable Found: String


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 Tto be a parcelable type?


Solution

  • 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.