• <bdo id='shHZ2'></bdo><ul id='shHZ2'></ul>
    1. <small id='shHZ2'></small><noframes id='shHZ2'>

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

        <tfoot id='shHZ2'></tfoot>
      1. <legend id='shHZ2'><style id='shHZ2'><dir id='shHZ2'><q id='shHZ2'></q></dir></style></legend>

        Java:&lt;init&gt; 之间有什么区别?和 &lt;clinit&gt;?

        时间:2023-08-23
        • <bdo id='C05zO'></bdo><ul id='C05zO'></ul>
            • <i id='C05zO'><tr id='C05zO'><dt id='C05zO'><q id='C05zO'><span id='C05zO'><b id='C05zO'><form id='C05zO'><ins id='C05zO'></ins><ul id='C05zO'></ul><sub id='C05zO'></sub></form><legend id='C05zO'></legend><bdo id='C05zO'><pre id='C05zO'><center id='C05zO'></center></pre></bdo></b><th id='C05zO'></th></span></q></dt></tr></i><div id='C05zO'><tfoot id='C05zO'></tfoot><dl id='C05zO'><fieldset id='C05zO'></fieldset></dl></div>
                <tbody id='C05zO'></tbody>

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

                <tfoot id='C05zO'></tfoot>

                • <legend id='C05zO'><style id='C05zO'><dir id='C05zO'><q id='C05zO'></q></dir></style></legend>
                  本文介绍了Java:&lt;init&gt; 之间有什么区别?和 &lt;clinit&gt;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我无法理解下面的文字...这是否意味着 <clinit> 用于空构造函数?为什么拥有两个不同的版本很重要?

                  https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html

                  <块引用>

                  <代码>2.9.特殊方法

                  在 Java 虚拟机级别,每个构造函数(第 2.12 节)都作为实例初始化方法出现,具有特殊名称 <init>.此名称由编译器提供.因为name <init> 不是一个有效的标识符,它不能直接用于用 Java 编程语言编写的程序.实例初始化方法只能在 Java 虚拟中调用机器由 invokespecial 指令,它们只能被调用在未初始化的类实例上.实例初始化方法获取构造函数的访问权限(第 2.7.4 节)它是派生出来的.

                  一个类或接口最多有一个类或接口初始化方法,并通过调用它来初始化(第 2.17.4 节)方法.类或接口的初始化方法是静态的并且不接受任何论点.它具有特殊名称 <clinit>.这个名字是由编译器提供.因为名称 <clinit> 不是有效的标识符,它不能直接在编写的程序中使用Java 编程语言.类和接口初始化方法由 Java 虚拟机隐式调用;他们从来不是直接从任何 Java 虚拟机 inw2struction 调用,但仅作为类初始化过程的一部分间接调用.

                  解决方案

                  <init> 是实例的(或其中之一)构造函数,非静态字段初始化.

                  <clinit> 是类的静态初始化块,以及静态字段初始化.

                  class X {静态日志 log = LogFactory.getLog();//<clinit>私人 int x = 1;//<初始化>X(){//<初始化>}静止的 {//<clinit>}}

                  I am unable to understand the following text... Does it mean that <clinit> is for empty constructors? Why is important to have two different versions?

                  https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html

                  2.9. Special Methods
                  

                  At the level of the Java virtual machine, every constructor (§2.12) appears as an instance initialization method that has the special name <init>. This name is supplied by a compiler. Because the name <init> is not a valid identifier, it cannot be used directly in a program written in the Java programming language. Instance initialization methods may be invoked only within the Java virtual machine by the invokespecial instruction, and they may be invoked only on uninitialized class instances. An instance initialization method takes on the access permissions (§2.7.4) of the constructor from which it was derived.

                  A class or interface has at most one class or interface initialization method and is initialized (§2.17.4) by invoking that method. The initialization method of a class or interface is static and takes no arguments. It has the special name <clinit>. This name is supplied by a compiler. Because the name <clinit> is not a valid identifier, it cannot be used directly in a program written in the Java programming language. Class and interface initialization methods are invoked implicitly by the Java virtual machine; they are never invoked directly from any Java virtual machine inw2struction, but are invoked only indirectly as part of the class initialization process.

                  解决方案

                  <init> is the (or one of the) constructor(s) for the instance, and non-static field initialization.

                  <clinit> are the static initialization blocks for the class, and static field initialization.

                  class X {
                  
                     static Log log = LogFactory.getLog(); // <clinit>
                  
                     private int x = 1;   // <init>
                  
                     X(){
                        // <init>
                     }
                  
                     static {
                        // <clinit>
                     }
                  
                  }
                  

                  这篇关于Java:&lt;init&gt; 之间有什么区别?和 &lt;clinit&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:获取正在运行的 JVM 的参数 下一篇:-XX:MaxPermSize 带或不带 -XX:PermSize

                  相关文章

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

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

                      <small id='kyinp'></small><noframes id='kyinp'>

                      <legend id='kyinp'><style id='kyinp'><dir id='kyinp'><q id='kyinp'></q></dir></style></legend>