<< Quote of the Day | Home | We Learn, We Marvel, We Forget, ... >>

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


Re: IDEA 4.0, J2SDK 1.5.0 Beta 1, Generify, ...

Can it turn this:
  Iterator iter = list.iterator();  
  while (iter.hasNext()) {
      I i = iter.next();
      System.out.println(i);
  } 
into this:
  for (I i : list) {
      System.out.println(i);
  }
I mean, if you're going to extol the virtues of Java 1.5, you might as well be consistent. :)

Re: IDEA 4.0, J2SDK 1.5.0 Beta 1, Generify, ...

Unfortunately not. It doesn't even recognize the "enhanced for" syntax. Nor does it recognize any of the other newer syntaxes (auto-boxing, annotations, etc.) To be fair, IDEA 4.0 does not claim to support JDK 1.5.0, only the add_generics-2_2-ea.zip compiler, when used with JDK 1.4.2.

Add a comment Send a TrackBack