类型参数不在其范围之内预期:发现可打包:字符串 [英] 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()
尝试将此类实现为
class MyDialogFragment : BaseDialogFragment<String>()
给我
Type argument is not within its bounds Expected: Parcelable Found: String
表示BaseDialogFragment<String>()
中的字符串.
那么,如何使用String
作为T
的值?如果我希望T
是可打包的类型,我的条件T: Parcelable
是否有点不对?
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?
推荐答案
那么,如何使用String作为T的值?
So, how can I use String as a value for T?
不能. String
不是Parcelable
,因为Parcel
已经知道如何处理String
.同样,您不能将ByteArray
用于T
,Int
或Boolean
.
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
.
这篇关于类型参数不在其范围之内预期:发现可打包:字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文