我正在尝试Parcelize数据类.它包含一个参数:
var tokenType: Any? = null
Run Code Online (Sandbox Code Playgroud)
对于这个变量编译器在编译时抱怨:
Type is not directoly supported by Parcelize.
Annotate the parater with @RawValue if you want it to be serialized via
writeValue()
Run Code Online (Sandbox Code Playgroud)
虽然错误是自我解释的,但当我添加@RawValue时:
@RawValue var tokenType: Any? = null
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:
This annotation is not applicable to target value parameter
Run Code Online (Sandbox Code Playgroud)
有关如何处理此问题的任何提示?
我在Kotlin帽子中有一个数据类,它正在使用@Parcelize注释进行简单的包裹。现在,我想将一个函数传递给此类,并且我真的不知道如何在打包期间不考虑该函数。
这是我的数据类:
@Parcelize
data class GearCategoryViewModel(
val title: String,
val imageUrl: String,
val categoryId: Int,
val comingSoon: Boolean,
@IgnoredOnParcel val onClick: (gearCategoryViewModel: GearCategoryViewModel) -> Unit
) : DataBindingAdapter.LayoutViewModel(R.layout.gear_category_item), Parcelable
Run Code Online (Sandbox Code Playgroud)
我尝试使用@IgnoredOnParcel,并@Transient没有成功。
这是我得到的编译错误:
错误:(20,39)'Parcelize'不直接支持类型。如果希望使用“ writeValue()”序列化参数类型,请使用“ @RawValue”注释参数类型
而且此@RawValue注释也不起作用。