2

Is there a way to convert Java code that uses generics to not use generics so it works on a pre-1.5 VM?

I want to convert JBox2D to run on BlackBerry, which doesn't support generics. I would prefer not to have to convert it manually.

3 Answers 3

3

There's nothing I'm aware of that will automatically re-write the source code to take out generics.

However, even though you don't want to make manual changes, the process can be made easier. Using Eclipse, any other major IDE, or even command-line options for raw javac itself... you can specify a target JRE version for your compiled output. Specify version 1.4.

The IDE or javac will then display errors for every point in the code using a feature (such as generics) unsupported prior to 1.5. That will at least take you straight to the exact files and line numbers that need to change... preventing guesswork and hunting on your part.

Sign up to request clarification or add additional context in comments.

1 Comment

Turns out it wasn't that much work to convert JBox2D thanks to Eclipse and some regex string replace.
0

Shouldn't be a problem. Just a lot of search, replace and casting. However; I'm don't think there is anything that will do this for you.

Comments

0

I did not try this (as I never worked on a 1.4 or earlier VM since I started using Generics), but often heard of Retroweaver being a good tool for exactly this purpose.

It works on the class file level, not source file level, though.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.