Encountered a strange problem while working on Eclipse [In the latest integration build - Version: 3.1.0 Build id: 200412081200]
I wrote a small snippet of code -
if(getContentSpec().equals("Test"))
return true;
The method getContentSpec was not implemented in the class; so it gave a compilation error. I took the QuickFix route and asked Eclipse to generate the stub for me. To my surprise, it generated the following code -
/**
* @return
*/
private AbstractList getContentSpec() {
// TODO Auto-generated method stub
return null;
}
I didn't really expect the method to return a String - but I at least expected it to return an Object. But it ended by returning an AbstractList!!!!! This was s t r a n g e!
To recreate the problem, before I submit the bug, I created a simple class -
public class QuickFixEquals {
public boolean hasChildren() {
return(getContentSpec().equals("Test"));
}
}
Applied QuickFix ... and the code generated was
private Object getContentSpec() {
// TODO Auto-generated method stub
return null;
}
Well, thats what I wanted in the original code ... why did it behave differently here?
I finally tracked it down to ... guess what? ... an import statement.
Try QuickFix on the following code
import java.util.List;It will generatepublic class QuickFixEquals {
public boolean hasChildren() { return(getContentSpec().equals("Test")); } }
private List getContentSpec() {
// TODO Auto-generated method stub
return null;
}
Better yet, try this code
import java.util.ArrayList; import java.util.List;Apply QuickFix, and lo, you get -public class QuickFixEquals {
public boolean hasChildren() { return (getContentSpec().equals("Test")); }
public List<String> getList() { return new ArrayList<String>(); } }
private AbstractList<E> getContentSpec() {
// TODO Auto-generated method stub
return null;
}
Here's the link to the QuickFix Bug.