@RawValue注释不适用于目标值参数 [英] @RawValue annotation is not applicable to target value parameter
问题描述
我正在尝试Parcelize
数据类.
它包含一个参数:
I am trying to Parcelize
a data class.
It contains one parameter :
var tokenType: Any? = null
对于此变量,编译器在编译时抱怨:
For this variable compiler complains at compile time that :
Type is not directoly supported by Parcelize.
Annotate the parater with @RawValue if you want it to be serialized via
writeValue()
虽然错误是自我解释的,但是当我添加@RawValue时,就像这样:
Though the error is self explainatory but when I add @RawValue like :
@RawValue var tokenType: Any? = null
它给出了一个错误:
This annotation is not applicable to target value parameter
关于如何处理此问题的任何提示?
Any hints on how to handle this?
推荐答案
我从Kotlang
社区获得了此问题的答案.
答案是您不能注释变量本身
但您必须注释其类型.
I got the answer to this problem from Kotlang
community.
Answer is you can not annotate the variable itself
but you have to annotate its type.
因此,通过以下方式注释可消除错误:
So annotating in the following way removes the error :
var tokenType: @RawValue Any? = null
尽管不要忘记为此属性手动编写serilizer/deserializer,因为它不会自动完成.
Though do not forget to write serilizer/deserializer for this property manually as it will not be done automatically.
希望有帮助.
这篇关于@RawValue注释不适用于目标值参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!