why does this code compile with eclipse compiler but not with javac (maven)

前端 未结 1 413
情歌与酒
情歌与酒 2021-02-09 03:08

There are a bunch of questions like this. I went through most of them but none actually but I couldn\'t come up with any answer:

I have a weird problem in one of my GWT/

相关标签:
1条回答
  • 2021-02-09 04:05

    Eclipse's compiler is actually a different compiler than the javac compiler. Sometimes they drift apart in behavior, usually they reconcile quickly.

    This was very noticable when Java's generics came out. There were cases where eclipse either found fault with a generics directive that javac would permit or javac found fault with generics that eclipse would permit (can't remember which way it drifted apart, too long ago). In either case, javac is more likely to be the correct implementation.

    In your case, you pollute the namespace with your generics reference to an inner class. Odds are that eclipse is reaching for the "View" in a different priority order than javac. Odds are excellent that either Javac implements the order as it is specified in the Java language guidelines, or the Java guidelines have not yet pronounced the "one true order" of resolving conflicting like-named classes. Normally this is not a problem because it is not permissible to use the same non-fully-qualified name in Java twice; however, with internal classes the specifications can be sort of "worked around".

    I would make the

    public interface MyView extends View {
    
    
    }
    

    bind to just one view (don't know if com.gwtplatform.mvp.client.View or MyPresenter.View is the right one) by making the name explicit.

    public interface MyView extends MyPresenter.View {
    
    
    }
    

    or

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

    That way you don't fall victim to the interface "binding" to the wrong type in a compiler-dependent manner.

    0 讨论(0)
提交回复
热议问题