gpt4 book ai didi

java - 无法在 RealmObject 子类中创建 ArrayList

转载 作者:行者123 更新时间:2023-12-01 17:56:58 27 4
gpt4 key购买 nike

我有一个类,它是 RealmObject 的子类,我想在该类中创建 arraylist,它将由 gson 反序列化,当我开始构建项目时出现编译时错误

Error:Type 'java.util.ArrayList<my_package.MessageContainerObject.Test>' of field 'messages' is not supported

这是我的课

open class MessageContainerObject : RealmObject() {
@SerializedName("from")
var from = ""
@SerializedName("messages")
var messages = ArrayList<Test>()

class Test
}

如果我删除父类,一切都会正常

最佳答案

您可以将消息定义为RealmList来自文档:

RealmList has two modes: A managed and unmanaged mode. In managed mode all objects are persisted inside a Realm, in unmanaged mode it works as a normal ArrayList.

https://realm.io/docs/java/latest/api/io/realm/RealmList.html

关于java - 无法在 RealmObject 子类中创建 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44019524/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com