文档对象上的 .remove 会导致 null 吗?
Does .remove on a document object result in a null?
在我的 java webagent 中,我创建了一个 Document 对象。
例如
NotesDocument 文档 = ...;
后来我在这个对象上使用删除:
document.remove(true);
之后我想检查文档是否为空,这样通常在该文档上运行的任何函数都不会被执行
例如:
if(document != null){
System.out.println(document.getItemValueString("ID"));
}
它仍然进入 if 语句及其语句:NotesException:对象已被删除或回收。
在这种情况下 != 是否无效?
您已经在此处的内存中创建了引用。
NotesDocument document = ...;
...
// Even you called document.remove(), it still exists because the code does not destroy the object and reference itself.
document.remove(true);
// That is why this still works.
if (document != null) {
System.out.println(document.getItemValueString("ID"));
}
您可以在调用 remove()
后显式分配 document = null;
,如果这是您指定要做的。
或
您可以检查文档的isDeleted()。例如if (!document.isDeleted())
.
在我的 java webagent 中,我创建了一个 Document 对象。 例如 NotesDocument 文档 = ...; 后来我在这个对象上使用删除:
document.remove(true);
之后我想检查文档是否为空,这样通常在该文档上运行的任何函数都不会被执行
例如:
if(document != null){
System.out.println(document.getItemValueString("ID"));
}
它仍然进入 if 语句及其语句:NotesException:对象已被删除或回收。
在这种情况下 != 是否无效?
您已经在此处的内存中创建了引用。
NotesDocument document = ...;
...
// Even you called document.remove(), it still exists because the code does not destroy the object and reference itself.
document.remove(true);
// That is why this still works.
if (document != null) {
System.out.println(document.getItemValueString("ID"));
}
您可以在调用 remove()
后显式分配 document = null;
,如果这是您指定要做的。
或
您可以检查文档的isDeleted()。例如if (!document.isDeleted())
.