Is it valid to have a JVM bytecode class without any constructor?

后端 未结 2 1764
醉话见心
醉话见心 2020-12-18 21:47

AFAIK, in Java implicit constructors are always generated for a class without constructors [1], [2].

But in bytecode I could not find such restriction on the JVMS.

2条回答
  •  难免孤独
    2020-12-18 22:21

    You've already answered the question yourself: a class without a constructor is absolutely valid according to JVMS. You cannot write such a class in pure Java, but it can be constructed using bytecode generation.

    Think of interfaces: they are also classes without a constructor from JVM point of view. And they can also have static members (you can even invoke interface's main method from the command line).

提交回复
热议问题