How to compile to target Java 1.0

前端 未结 2 1883
别跟我提以往
别跟我提以往 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条回答
  •  萌比男神i
    2021-02-09 23:31

    In Java 8 the minimum target is JDK 1.1. In Java 9 the minimum target was increased JDK 1.6 (Java 6).

    Its a good thing you are trying to make your code compatible with as many java versions as possible, but since Java 6 has been out of service since 2015, really nobody should be trying to write new code that runs with Java 5 or older.

    EDIT: Also, in Java 9 they introduced the --release flag in Javac, which is the preferred option instead of -source and -target now. Basically --release 6 is the same thing as -source 1.6 -target 1.6, but it also has the added benefit of setting your bootclasspath in conjunction with the target release, which is a huge convenience. In practice this protects you from setting --release 6 in the compiler, but accidentally using some new class or language feature from Java 7 or higher.

提交回复
热议问题