@RawValue注释不适用于目标值参数

编程入门 行业动态 更新时间:2024-10-25 12:24:56
本文介绍了@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注释不适用于目标值参数

本文发布于:2023-11-30 12:01:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649876.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目标值   注释   不适用于   参数   RawValue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!