<i id='g8Mxh'><tr id='g8Mxh'><dt id='g8Mxh'><q id='g8Mxh'><span id='g8Mxh'><b id='g8Mxh'><form id='g8Mxh'><ins id='g8Mxh'></ins><ul id='g8Mxh'></ul><sub id='g8Mxh'></sub></form><legend id='g8Mxh'></legend><bdo id='g8Mxh'><pre id='g8Mxh'><center id='g8Mxh'></center></pre></bdo></b><th id='g8Mxh'></th></span></q></dt></tr></i><div id='g8Mxh'><tfoot id='g8Mxh'></tfoot><dl id='g8Mxh'><fieldset id='g8Mxh'></fieldset></dl></div>

<legend id='g8Mxh'><style id='g8Mxh'><dir id='g8Mxh'><q id='g8Mxh'></q></dir></style></legend>
  • <small id='g8Mxh'></small><noframes id='g8Mxh'>

      <bdo id='g8Mxh'></bdo><ul id='g8Mxh'></ul>

      1. <tfoot id='g8Mxh'></tfoot>

        JVM 什么时候决定重用旧的 lambda?

        时间:2023-08-24

          <i id='qZ7UL'><tr id='qZ7UL'><dt id='qZ7UL'><q id='qZ7UL'><span id='qZ7UL'><b id='qZ7UL'><form id='qZ7UL'><ins id='qZ7UL'></ins><ul id='qZ7UL'></ul><sub id='qZ7UL'></sub></form><legend id='qZ7UL'></legend><bdo id='qZ7UL'><pre id='qZ7UL'><center id='qZ7UL'></center></pre></bdo></b><th id='qZ7UL'></th></span></q></dt></tr></i><div id='qZ7UL'><tfoot id='qZ7UL'></tfoot><dl id='qZ7UL'><fieldset id='qZ7UL'></fieldset></dl></div>
            <tbody id='qZ7UL'></tbody>
        1. <small id='qZ7UL'></small><noframes id='qZ7UL'>

          <legend id='qZ7UL'><style id='qZ7UL'><dir id='qZ7UL'><q id='qZ7UL'></q></dir></style></legend>
          • <bdo id='qZ7UL'></bdo><ul id='qZ7UL'></ul>
            <tfoot id='qZ7UL'></tfoot>

                • 本文介绍了JVM 什么时候决定重用旧的 lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  考虑以下代码片段:

                  public static Object o = new Object();
                  
                  public static Callable x1() {
                      Object x = o;
                      return () -> x;
                  }
                  
                  public static Callable x2() {
                      return () -> o;
                  }
                  

                  方法 x2() 将始终返回相同的 Lamba 对象,而 x1() 将始终创建新对象:

                  Method x2() will always return the same lamba object, while x1() will always create new one:

                      System.out.println(x1());
                      System.out.println(x1());
                      System.out.println(x2());
                      System.out.println(x2());
                  

                  会打印出如下内容:

                  TestLambda$$Lambda$1/821270929@4a574795
                  TestLambda$$Lambda$1/821270929@f6f4d33
                  TestLambda$$Lambda$2/603742814@7adf9f5f
                  TestLambda$$Lambda$2/603742814@7adf9f5f
                  

                  在哪里(我猜是在 JVM 规范中?)描述了这个 lambda 重用规则?JVM如何决定在哪里重用?

                  Where (in JVM specification I guess?) is this rule of lambda reuse described? How does JVM decide where do reuse or not?

                  推荐答案

                  您无法确定为 lambda 表达式返回的对象的身份.它可以是新实例,也可以是预先存在的实例.

                  You can't be sure about the identity of the object returned for a lambda expression. It can be a new instance, or a pre-existing instance.

                  这在 中指定JLS §15.27.4:

                  在运行时,对 lambda 表达式的求值类似于对类实例创建表达式的求值,只要正常完成产生对对象的引用.lambda 表达式的求值不同于 lambda 主体的执行.

                  At run time, evaluation of a lambda expression is similar to evaluation of a class instance creation expression, insofar as normal completion produces a reference to an object. Evaluation of a lambda expression is distinct from execution of the lambda body.

                  要么分配并初始化具有以下属性的类的新实例,要么引用具有以下属性的类的现有实例.如果要创建一个新实例,但没有足够的空间来分配对象,则 lambda 表达式的计算会通过抛出 OutOfMemoryError 突然完成.

                  Either a new instance of a class with the properties below is allocated and initialized, or an existing instance of a class with the properties below is referenced. If a new instance is to be created, but there is insufficient space to allocate the object, evaluation of the lambda expression completes abruptly by throwing an OutOfMemoryError.

                  这篇关于JVM 什么时候决定重用旧的 lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Java 11 时 JDK_JAVA_OPTIONS 和 JAVA_TOOL_OPTIONS 有什么区别? 下一篇:Java Attach API:动态更改 java.library.path

                  相关文章

                  • <bdo id='nUtq1'></bdo><ul id='nUtq1'></ul>

                    <legend id='nUtq1'><style id='nUtq1'><dir id='nUtq1'><q id='nUtq1'></q></dir></style></legend>
                  1. <i id='nUtq1'><tr id='nUtq1'><dt id='nUtq1'><q id='nUtq1'><span id='nUtq1'><b id='nUtq1'><form id='nUtq1'><ins id='nUtq1'></ins><ul id='nUtq1'></ul><sub id='nUtq1'></sub></form><legend id='nUtq1'></legend><bdo id='nUtq1'><pre id='nUtq1'><center id='nUtq1'></center></pre></bdo></b><th id='nUtq1'></th></span></q></dt></tr></i><div id='nUtq1'><tfoot id='nUtq1'></tfoot><dl id='nUtq1'><fieldset id='nUtq1'></fieldset></dl></div>

                    1. <small id='nUtq1'></small><noframes id='nUtq1'>

                      <tfoot id='nUtq1'></tfoot>