gpt4 book ai didi

java - 在 session.close() 之后设置 session=null 是否有意义?

转载 作者:太空宇宙 更新时间:2023-11-04 10:12:28 25 4
gpt4 key购买 nike

考虑这段代码:

public void foo(){
try{
//some cool statements here
}
finally {
if(session != null){
session.close();
sesssion = null;
}
}
}

既然 session 关闭了,分配给 session 的值还有意义吗?请提供一些有值(value)的见解。

最佳答案

将局部变量设置为 null 是不必要的,也就是说,它是 CERT Oracle 安全编码标准 Recommendations 的一部分。

Setting local reference variables to null to "help the garbage collector" is unnecessary. It adds clutter to the code and can make maintenance difficult. Java just-in-time compilers (JITs) can perform an equivalent liveness analysis, and most implementations do so.

关于java - 在 session.close() 之后设置 session=null 是否有意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52150347/

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