根据JLS:
类或接口类型T将在第一次出现以下任何一个之前立即初始化:
T是一个类,并且创建了T的实例.
它也说,
类的初始化包括执行其静态初始化程序和类中声明的静态字段(类变量)的初始化程序
我从中推断出两点
现在,
我假设当我在自己的(Test自己的)静态初始化程序中创建一个类Test的对象时,它应该抛出一个堆栈溢出,因为它应该重复调用自身,因为根据上面两点,类的实例化应该初始化类和初始化块具有类的实例化.当我在自己的构造函数或其自己的实例初始化程序中实例化类时,会发生堆栈溢出.
例如,
public class Test {
static{
System.out.println("static test");
new Test();
}
{
//new Test(); // This will give a stack overflow
System.out.println("intializer");
}
public Test(){
//new Test(); // This will give a stack overflow
System.out.println("constructor");
}
public static void main(String[] args) {
}
}
Run Code Online (Sandbox Code Playgroud)
然而,结果是不同的.
结果:
静态测试初始化构造函数
要么我太困惑了解课程的初始化,要么如果我在这里遗漏一些非常明显的东西并且感谢你的帮助,我会道歉.
As per the link : /sf/answers/89690681/
I followed the instructions and created a jar file, the input directory where the source files for creating the jar is as follows,
when i am traversing through JarFile#entries method it is printing the following,
META-INF/MANIFEST.MF
D:/so/
D:/so/some.txt
but i created the jar file using jar tool
jar -cvf so_commond.jar so so/some.txt
added manifest
adding: so/(in = …
我在Spring 4.0.0 M3上教育自己以下是代码,
豆
package org.chebus.springs;
import java.util.Date;
public class Traingle {
private String name;
private int height;
private Date date;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public void drawShape() {
System.out.println(getName() + " Traingle height " + …Run Code Online (Sandbox Code Playgroud)