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

最后都变了- 提交于 2020-05-29 09:44:17

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!