@RawValue注释不适用于目标值参数 [英] @RawValue annotation is not applicable to target value parameter

查看:1086
本文介绍了@RawValue注释不适用于目标值参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆