How to compile to target Java 1.0

前端 未结 2 1851
别跟我提以往
别跟我提以往 2021-02-09 23:11

I want to compile my code down to Java version 1.0.

I managed to compile down to 1.1:

$ java -version
openjdk version \"1.8.0_181\"
OpenJDK          


        
2条回答
  •  名媛妹妹
    2021-02-09 23:14

    TL;DR javac -target 1.1 (and not using any classes or methods that were added later) will make it work on JDK >=1.0.2 (released on 1995-09-16). It's not feasible to go back more, because earlier JDKs are not publicly available to try.

    The javac -target ... flag value affects the minor (byte offset 4 and and 5) and major (byte offset 6 and 7) version number stored in the .class file:

    • javac -target 1.1 in JDK 1.8 generates version 45.3, supported by JDK 1.0.2 (released on 1995-09-16), JDK 1.1.* (released in 1997-02), JDK >=1.2 (released in 1998-12). [source]
    • javac in JDK 1.0.2 (from jdk-1_0_2-win32-x86.exe, run with wine on Linux) generates version 45.3.
    • For k ≥ 2, JDK release 1.k supports class file format versions in the range 45.0 through (44+k).0 inclusive. [source]
    • javac -target 1.2 generates version 46.0, supported by JDK >=1.2.
    • javac -target 1.3 generates version 47.0, supported by JDK >=1.3.
    • javac -target 1.4 generates version 48.0, supported by JDK >=1.4.
    • etc.

提交回复
热议问题