Java: What is the difference between <init> and <clinit>?
Stack Overflow 上的一个问题:Java: What is the difference between <init> and <clinit>?

At the level of the Java Virtual Machine, every constructor written in the Java programming language (JLS §8.8) 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 (§invokespecial), and they may be invoked only on uninitialized class instances. An instance initialization method takes on the access permissions (JLS §6.6) of the constructor from which it was derived.A class or interface has at most one class or interface initialization method and is initialized (§5.5) by invoking that method. The initialization method of a class or interface has the special name
<clinit>, takes no arguments, and is void (§4.3.3).Other methods named
<clinit>in aclassfile are of no consequence. They are not class or interface initialization methods. They cannot be invoked by any Java Virtual Machine instruction and are never invoked by the Java Virtual Machine itself.In a
classfile whose version number is 51.0 or above, the method must additionally have itsACC_STATICflag (§4.6) set in order to be the class or interface initialization method.This requirement was introduced in Java SE 7. In a class file whose version number is 50.0 or below, a method named
<clinit>that is void and takes no arguments is considered the class or interface initialization method regardless of the setting of itsACC_STATICflag.The name
<clinit>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 instruction, but are invoked only indirectly as part of the class initialization process.
Java: What is the difference between <init> and <clinit>?的更多相关文章
- JVM思考-init和clinit区别
JVM思考-init和clinit区别 目录:JVM总括:目录 clinit和init的区别其实也就是Class对象初始化对象初始化的区别,详情看我上一篇博客: JVM总括四-类加载过程.双亲委派模型 ...
- 深入理解jvm--Java中init和clinit区别完全解析(转)
转自:http://blog.csdn.net/u013309870/article/details/72975536 init和clinit区别 ①init和clinit方法执行时机不同 init是 ...
- <init>与<clinit>,static与final与static final
<init>和<clinit> init是对象构造器方法,初始化对象的时候执行 clinit是类构造器方法,类加载的初始化阶段执行 final常量赋值(必须是一下其中一种) 显 ...
- Java Virtual Machine (JVM), Difference JDK, JRE & JVM – Core Java
By Chaitanya Singh | Filed Under: Learn Java Java is a high level programming language. A program wr ...
- <init>与<clinit>的区别
在编译生成class文件时,会自动产生两个方法,一个是类的初始化方法<clinit>, 另一个是实例的初始化方法<init> <clinit>:在jvm第一次加载c ...
- Java <clinit> & <init>
在编译生成class文件时,会自动产生两个方法,一个是类的初始化方法<clinit>, 另一个是实例的初始化方法<init>. <clinit>:在jvm第 ...
- Invocation of init method failed; nested exception is java.text.ParseException: '?' can only be specfied for Day-of-Month or Day-of-Week.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cronTrigger' ...
- java执行顺序之深入理解clinit和init
原文地址:https://blog.csdn.net/qq_36522306/article/details/80582758 前言: 最近研究了深入理解JVM这本书中的知识,对java中各部分执行的 ...
- 200个最常见的JAVA面试问题(附答案)
本文内容: 20个最常见的JAVA面试问题(附答案) 13个单例模式JAVA面试问题(附答案) 说说JVM和垃圾收集是如何工作的(附答案) 说说如何避免JAVA线程死锁(附答案) Java中HashS ...
随机推荐
- 常用 GDB 命令中文速览
转自:https://linux.cn/article-8900-1.html?utm_source=index&utm_medium=moremore 目录 break -- 在指定的行或函 ...
- 4950: [Wf2017]Mission Improbable
4950: [Wf2017]Mission Improbable Time Limit: 1 Sec Memory Limit: 512 MBSubmit: 608 Solved: 222[Sub ...
- 发现程序bug思路
大家有没有遇到过项目,程序出现个bug,但花了好久(真的是a long long time啊)才发现引发这个问题的原因,心想原来就这个原因导致的啊,要是早想到就好了! 其实我们确实的是方法,希望我的抛 ...
- HDFS文件访问权限
HDFS中的文件访问权限 针对文件和目录,HDFS的权限模式与POSIX非常相似一共提供三类权限模式:只读权限(r).写入权限(w)和可执行权限(x).读取文件或列出目录内容时需要只读权限.写入一个文 ...
- IOS 被拒 关于 iPhone running iOS 10.3.1 on Wi-Fi connected to an IPv6 network.
问题: Guideline 2.1 - Performance Thank you for your resubmission. However, we discovered one or more ...
- cdq分治入门and持续学习orz
感觉cdq分治是一个很有趣的算法 能将很多需要套数据结构的题通过离线来做 目前的一些微小的理解 在一般情况下 就像求三维偏序xyz 就可以先对x排序 然后分治 1 cdq_x(L,M) ; 2 提取出 ...
- JavaWeb -- Jsp 自定义标签的使用
Jsp中不要有一行Java代码, 需要的Java代码都要封到自定义标签中. 自定义标签的作用: a. 自定义标签除了可以移除jsp页面java代码外,它也可以实现以上功能. b. 控制jsp页面某 ...
- 平衡二叉树--java
package com.test.tree; /** * 带有平衡条件的二叉查找树 * */ public class AVLBinarySearchTree<T extends Compara ...
- MySQL 体系结构和存储引擎
数据库: 物理操作系统文件或其他形式文件类型的集合 实例: MySQL数据库向后台线程以及一个共享内存区组成,共享内存可以被运行的后台线程所共享 MySQL 数据库实例在某统上的表现就是一个进程. M ...
- 分享知识-快乐自己:Spring线程池配置
Spring通过ThreadPoolTaskExecutor实现线程池技术,它是使用jdk中的Java.util.concurrent.ThreadPoolExecutor进行实现. Spring 配 ...