java - 下面的代码片段中发生了什么?

标签 java

我无法理解以下片段。我的意思是到底发生了什么。谁能解释一下发生了什么?

这是片段:

protected NodeService getUnprotectedNodeService()

   { 

      if (this.unprotectedNodeService == null)
          {
         this.unprotectedNodeService = (NodeService) FacesHelper.getManagedBean(FacesContext.getCurrentInstance(), "nodeService");
      }
      return this.unprotectedNodeService;
   }

最佳答案

如果尚未设置,它会设置 this.unprotectedNodeService (并且还会返回它..),如果已经设置,它只会返回它。
似乎是一种缓存机制,可以防止多次调用重型方法

关于java - 下面的代码片段中发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6263242/

相关文章:

java - 在gradle中添加compileJava任务的插件

java - JBoss EAP 6.2 JMX 服务器和注册表绑定(bind)

Java 和 C : How can I compile this C source file into a DLL for use with Java?

java - 是否可以在非主线程中创建 openGL VBO/显示列表

java - 如何使用自定义登录模块捕获响应状态 Tomcat JaasRealm

java - tomcat6 apache cxf javax.net.ssl.SSLPeerUnverifiedException : peer not authenticated

Java sql char 准备好的语句

java - Spring 验证失败时枚举字段上的自定义错误消息

java - 检查表是否存在

java - 在@RestController 上使用 Spring Caching 注解