Compiling Java code written for 1.5 to work with 1.4 JRE?

后端 未结 4 1950
抹茶落季
抹茶落季 2021-01-05 05:21

I have a project that uses generics and a few Java 1.5/6 bits and pieces. Is it possible to compile this code to work on a system running a 1.4 JRE?

I use an ANT bui

相关标签:
4条回答
  • 2021-01-05 06:03

    Generics are implemented by type erasure so they should work before generics were introduced. However you would be unable to compile the code with an older version of the compiler (I don't know why you would want to do that)

    0 讨论(0)
  • 2021-01-05 06:05

    I have a project that uses generics and a few Java 1.5/6 bits and pieces. Is it possible to compile this code to work on a system running a 1.4 JRE?

    No.

    Am I going to have to go through all my code and change the 1.5 stuff to make this work?

    Yes. But there's a way to automate that, using a tool called Retroweaver. There's no guarantee that it will catch everything though.

    0 讨论(0)
  • 2021-01-05 06:11

    I have had good experience with Retrotranslator (retroweaver did not work well with what I was needing, cannot remember exactly what).

    It worked very well for my purpose (creating JDK1.4 versions of Logback).

    http://retrotranslator.sourceforge.net/

    0 讨论(0)
  • 2021-01-05 06:12

    I've not used either of these solutions, but there is

    1. Retroweaver
    2. specifying the unsupported -target jsr14 may work
    3. Retrotranslator
    4. Declawer
    5. JBossRetro

    You might also find javac -XD-printflat useful (though take care not to overwrite your original source).

    0 讨论(0)
提交回复
热议问题