我使用Realm在我的项目中存储数据。我有奇怪的问题。 我的模特:
Class Post extends RealmObject implements Serializable{
@PrimaryKey
int id;
...
RealmList<Post> subdata;
RealmList<Post> getSubdata() {
return subdata;
}
}
我经常检查getSubdata() != null && getSubdata().isValid()
以使用子数据。问题是当我检查getSubdata().isValid()
返回false
时,我仍然会在subdata
中获取数据。我没有检查isValid
时没关系。文件说的像这样:
/**
* Checks if the {@link RealmList} is managed by Realm and contains valid data i.e., the {@link io.realm.Realm}
* instance hasn't been closed.
*
* @return {@code true} if still valid to use, {@code false} otherwise or if it's an unmanaged list.
*/
public boolean isValid() {
//noinspection SimplifiableIfStatement
if (realm == null || realm.isClosed()) {
return false;
}
return isAttached();
}
更新调试:
https://uk.mathworks.com/help/matlab/math/matrix-indexing.html
答案 0 :(得分:0)
您的类需要扩展RealmObject。所以它应该改为:
Class Post extends RealmObject {
@PrimaryKey
int id;
...
RealmList<Post> subdata;
RealmList<Post> getSubdata() {
return subdata;
}
}