Is Java bytecode compatible with different versions of Java?

前端 未结 3 1734
粉色の甜心
粉色の甜心 2021-01-21 08:30

If I compile an application using Java 5 code into bytecode, are the resulting .class files going to be able to run under Java 1.4?

If the latter can wo

3条回答
  •  不知归路
    2021-01-21 09:28

    No. You can only move upwards - Java 1.4 bytecode will work on Java 5 runtimes. However, if you aren't using any functionality not found in Java 1.4, you can compile using the -target and -source options of javac.

    If you want to use Java 5 to write an application that can be run on Java 4, you can't use any features that weren't present before Java 5.

提交回复
热议问题