Java Question about a .class generated with Java 14

chiperortiz :

I have a simple class like this.

class ClassWithDefaultConstructor{}

I am working with this jdk.

C:\JavaSE14Folder>java -version
java version "14" 2020-03-17
Java(TM) SE Runtime Environment (build 14+36-1461)
Java HotSpot(TM) 64-Bit Server VM (build 14+36-1461, mixed mode, sharing)

As you can see i am using the latest version of the Jdk.

I create this .class like this.

C:\JavaSE14Folder>javac -d . ClassWithDefaultConstructor.java

The .class is created later on i try this command.

C:\JavaSE14Folder>javap ClassWithDefaultConstructor.class

And i see the following

Compiled from "ClassWithDefaultConstructor.java"
class ClassWithDefaultConstructor {
   ClassWithDefaultConstructor();
}

Two things here mades me happy first the default constructor is created and i see that the visibility of the constructor is the same of the class that's great but 3 things made feel sad :(

My questions are.

1). Why the constructor has no body and terminates with ;
2). Why the constructor hasn't a call to the java.lang.Object constructor?;
3). Why this class is not extending java.lang.Object

I did expect something like this.

class ClassWithDefaultConstructor extends java.lang.Object {
   ClassWithDefaultConstructor(){
       super();
   }
}

I expected a bytecode something like this post.

Post

Perhaps i missed something please be kind.

:) Best regards from Venezuela.

If i put the command like this.

C:\JavaSE14Folder>javap -c ClassWithDefaultConstructor.class
Compiled from "ClassWithDefaultConstructor.java"
class ClassWithDefaultConstructor {
 ClassWithDefaultConstructor();
 Code:
   0: aload_0
   1: invokespecial #1                  // Method java/lang/Object." 
<init>":
()V
   4: return
}

Is different but still i dont see my stuff like extending Object and so.

I would love see something like this at least like in the post.

Compiled from "test.java"
public class test extends java.lang.Object{

In resume i dont see the compiler inserting those implicit lines.

In this Java Question about a .class generated with Java 14 states that happens the same on the newer versions of Java.

Same output using

C:\Program Files\Java\jdk1.8.0_121\bin
Antimony :

Bytecode != Java source code.

What is actually in the classfile is just random bytes. What you are seeing is javap's textual representation of the bytecode, which is designed to be familiar to Java programmers who don't know much about bytecode, and hence uses Java like syntax where possible. But it is not and is not meant to be actual Java source code.

If you used a different disassembler such as Krakatau, the output would look very different, but it would still be a representation of the same binary classfile.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=393623&siteId=1