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 ...
随机推荐
- 如何用hexo+github搭建个人博客
搭建环境 1.安装 Node.js: https://nodejs.org/en/ windows下点击链接,下载安装即可;Linux下更加简单,在终端下输入sudo apt-get install ...
- Jsp&Servlet实现读取本地图片并展示
在Web开发中图片的读取和展示是一个很常见的功能,实现的过程大致也都一样(包括在各种框架中--)!接下来用流的方式来实现图片的展示 1. 创建Servlet,实现读取,请求方式使用get请求: p ...
- 在环境变量里设置VI中TAB缩进
终端上的tab键默认是缩进8个空格的(记住8个空格不等于一个tab, tab和空格不是一个概念) 一般设置vim的tab(制表符)的缩进的时候都这样:set tabstop=4 ” 表示让tab的宽度 ...
- Ubuntu linux背景指南:在开始之前需要知道哪些东西
1.摘要 Ubuntu是一个新的GNU/Linux衍生操作系统,其目标是更多地以用户为本以及桌面应用. 因此,Ubuntu的目的是消除安装的困难,在很大程度上靠自动配置和自动探测硬件解决 问题,无须用 ...
- 更改自己iCloud的地区
百度一大堆都是过时的,而且没有用,通过google后发现google+里有一个文章https://plus.google.com/+%E5%90%B4%E5%BF%97%E5%8B%8776/post ...
- Node.js初接触(一)
本来还在纠结着到底要学哪一种后台语言呢,突然发现node.js很火,既然能被这么多人推崇,自然是有他的优势的.去百度百科看了一眼,或许是我理解能力太差,并没有了解到很多关于node.js的东西,大概就 ...
- hdu2665 主席树(可持久化线段树)
题意:给定一个数组,每次查询第l到r区间的第k大值 解法嘛,当然是主席树,主席树即可持久化线段树,什么叫可持久化呢,就是指能够访问历史版本的数据结构,那么对于某些只能离线处理的题目强制在线之后 ,可以 ...
- ural 2016 Magic and Science
2016. Magic and Science Time limit: 1.0 secondMemory limit: 64 MB Scientists who specialize in witch ...
- hdu 2149 Public Sale(bash)
Public Sale Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- NSObject头文件解析 / 消息机制 / Runtime解读 (二)
本章接着NSObject头文件解析 / 消息机制 / Runtime解读(一)写 给类添加属性: BOOL class_addProperty(Class cls, const char *name, ...