Atom Feed SITE FEED   ADD TO GOOGLE READER

Burned by wildcard imports and SwingWorker

The following code uses com.publicobject.swing.SwingWorker from the Java tutorial:
package com.publicobject.demo;

import com.publicobject.swing.*;
import javax.swing.*;

public class HelloWorldWorker extends SwingWorker {
private final JLabel label;
public HelloWorldWorker(JLabel label) {
this.label = label;
}
public Object construct() {
return "Hello World";
}
public void finished() {
label.setText((String)get());
}
}


It compiles fine under Java 5. But in Java 6, it doesn't even compile! The problem is that the two imports conflict - there's my SwingWorker, and the one Mustang provides in its javax.swing package. If you're using SwingWorker, you should fully qualify your imports now so when Java 6 comes, you're ready.
I found that since using a Java IDE this type of problem goes away. In my Java/Vim days then I'd use the wildcard because I was too lazy to type out all the classes I needed. But the IDEs just get on and include them, one-by-one as you need em :)