IDEA 4.0, J2SDK 1.5.0 Beta 1, Generify, ...
Got my brand new IDEA 4.0 today, and immediately saw the "Generify..." Refactoring. Given:
interface I {}
class A implements I {}
It turns code like this:
List list = new ArrayList();
list.add(new A());
Iterator iter = list.iterator();
while (iter.hasNext()) {
I i = (I) iter.next();
System.out.println(i);
}
into this:
List<I> list = new ArrayList<I>();
list.add(new A());
Iterator<I> iter = list.iterator();
while (iter.hasNext()) {
I i = iter.next();
System.out.println(i);
}
You can even select multiple classes from the Project Tool Window, and select Refactor | Generify from the context menu to have it done to all of them. Really slick!
Figuring out how to use the 1.5.0 compiler with IDEA 4.0 is a little bit challenging because the documentation still talks about the add_generics-2_2-ea.zip and the gjc-rt.jar and collect.jar files therein.
It turns out, with the 1.5.0 compiler, you don't have to do any of that. Simply:
- Select 1.5.0 as the compiler for the project as you would normally do
- Uncheck the "Use generics-enabled compiler" check box in Compiler settings dialog box
- Add "-source 1.5" to the "Additional javac command line parameters" field