Why is this code compiling with the eclipse compiler, but not with javac (maven)

There are questions like this. I went through most of them, but no one really, but I could not come up with any answer:

I have a weird problem in one of my GWT / GWTP classes.
The class is compiled using the Eclipse compiler, but not with the javac (Maven) compiler.

//additional imports import com.gwtplatform.mvp.client.PresenterWidget; import com.gwtplatform.mvp.client.View; public class MyPresenter extends PresenterWidget<MyPresenter.MyView> { public interface MyView extends View { } some code } 

When I try to compile with maven, I get the following error:

cannot find character symbol: class View

The view refers to the View interface in the com.gwtplatform.mvp.client package.

I have other classes that look the same and work great.
The strange thing is that if I change the import order or I specify the exact package of the View interface that it compiles without any problems in maven.
To be specific, I moved the import for com.gwtplatform.mvp.client.View

 import com.gwtplatform.mvp.client.View; //additional imports import com.gwtplatform.mvp.client.PresenterWidget; 

I had a similar problem some time ago with the problem of circular inheritance between classes that belong to inner classes (working in eclipse but not in javac). However, I'm not sure if this is the same problem.

+7
source share
1 answer

The Eclipse compiler is actually a different compiler than the javac compiler. Sometimes they drift in behavior, usually they migrate quickly.

This was very noticeable when Java generics appeared. There were times when eclipse either detected a bug in the generics directive that javac resolved, or javac found a bug regarding generics that would allow an eclipse (I don’t remember how it drifted separately, too long ago). In any case, javac will most likely be the correct implementation.

In your case, you pollute the namespace with a link to the common code for the inner class. The likelihood that an eclipse reaches View is in a different order of priority than javac. The odds are excellent that either Javac implements the order, as described in the Java language manual, or the Java guidelines have not yet declared a “one true order” for resolving conflicting classes with a name. This is usually not a problem because it is not permissible to use the same incompletely qualified name in Java twice; however, with inner classes, specifications can be “processed”.

I would do

 public interface MyView extends View { } 

attached to one view (I don’t know if com.gwtplatform.mvp.client.View or MyPresenter.View correct), specifying the name explicitly.

 public interface MyView extends MyPresenter.View { } 

or

 public interface MyView extends com.gwtplatform.mvp.client.View { } 

Thus, you do not fall prey to the binding interface to the wrong type, depending on the compiler.

+8
source

All Articles