Question

I can't get it. I have a common problem in Eclipse, when trying to organize Imports for the whole Project. Short example for clearification

package test.somepackage
class A{

    public B getB(){ return new B() }
}

package test.somepackage
class B{} 

package foobar
class B {}

package somewhere.in.code
class ClientUsingAAndB {

    public void someMethod(){

        A a = new A()
        //here Eclipse gets an "Organize Import Conflict"
        B b = a.getB();

    }
}

So if I try to automatically "Organize Imports" Eclipse is asking me If I want to import test.somepackage.B or foobar.B. For me its very clear which one, and if I tell Eclipse to use foobar.B Eclipse immediatly complains about non matching return types. Thing is: If Eclipse already knows which return type it gets (from class A signature) why it acts like stupid? Also if I just type a.getB() hover over it, and tell Eclipse to "Assign Statement to new local variable" (strg+1), It automatically infers the correct type and adds the import.

Whats happening? Is this some kind of the annoying Eclipse bugs noone wants to fix, or do I want too much from my IDE?

EDIT: If there is something not really clear, please comment it, and I'll try to provide nessesary information

Was it helpful?

Solution

This is a long-standing request (going back to 2005). See this Eclipse report that is stagnant. Perhaps you could get involved and help address it. I know the JDT team would welcome contributions for these kinds of small enhancements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top