我正在尝试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注释不适用于目标值参数
发布评论