java - 编译时JVM不提供构造函数

标签 java

当我们在类中创建任何构造函数(无论是默认构造函数还是带参数构造函数)时,JVM 为什么在编译时不提供构造函数?

最佳答案

以下是 Java 语言规范的摘录:

If a class contains no constructor declarations, then a default constructor that takes no parameters is automatically provided:

  • If the class being declared is the primordial class Object, then the default constructor has an empty body.
  • Otherwise, the default constructor takes no parameters and simply invokes the superclass constructor with no arguments.

事实上,只要类不包含构造函数声明,JVM 就会“提供”默认构造函数。与此相同

public MyClass() {}

关于java - 编译时JVM不提供构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3235277/

相关文章:

java - DecimalFormat 没有分组分隔符

java - 如何从 h :message 中删除点( ListView )

java - String.replaceFirst 不同的行为

java - 扫描仪返回未找到行

java.io.IOException : Failed to delete original file moveFileToDirectory

java - 用于跨程序复制/粘贴的用户定义字符串

java - 解决JSP中的并发问题

java - 添加 @ComponentScan 从 jar 加载 bean 后,我的 Controller 未扫描,并且收到 404

java - Android如何在单击按钮时更改底部导航项的颜色

java - Android 谷歌地图 v2 : resize polygon