为什么这个代码用eclipse编译器编译而不是用javac(maven) [英] why does this code compile with eclipse compiler but not with javac (maven)

查看:194
本文介绍了为什么这个代码用eclipse编译器编译而不是用javac(maven)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有很多问题。我经历了大多数人,但没有实际,但我不能提出任何答案:



我有一个奇怪的问题,在我的一个GWT / GWTP类。 br>
该类使用Eclipse编译器进行编译,但是使用javac编译器(Maven)失败。

  //额外汇入
import com.gwtplatform.mvp.client.PresenterWidget;
import com.gwtplatform.mvp.client.View;

public class MyPresenter extends PresenterWidget< MyPresenter.MyView> {

public interface MyView extends View {


}

一些代码
}

当我尝试使用maven编译时,我得到以下错误:


找不到符号符号:class View


>是指 com.gwtplatform.mvp.client 包中的 View 界面。



我有其他类看起来一样,工作正常。

奇怪的是,如果我改变了导入的顺序或者我指定的确切的包的查看接口它编译没有任何问题在maven。

具体来说,我移动了导入 com.gwtplatform.mvp.client。查看

  import com.gwtplatform.mvp.client.View; 
//其他导入
import com.gwtplatform.mvp.client.PresenterWidget;

我有一个类似的问题,一些时间以前循环继承问题在类之间引用内部类在eclipse但没有在javac)。但是我不知道这是否是同样的问题。

解决方案

Eclipse的编译器实际上是一个不同于javac编译器的编译器。有时他们在行为上分开,通常他们很快调和。



当Java的泛型出来时,这是非常值得注意的。有些情况下,eclipse发现javac允许的泛型指令的错误,或者javac发现eclipse允许的泛型的错误(不记得哪种方式漂移了,很久以前)。在任何一种情况下,javac更可能是正确的实现。



在你的情况下,你使用对一个内部类的泛型引用来污染命名空间。奇怪的是,eclipse到达的视图在不同的优先级顺序比javac。奇怪的是,Javac实现的顺序,因为它是在Java语言指导方针中指定的,或者Java指南还没有发现解决冲突的同名类的一个真正的顺序。通常这不是一个问题,因为不允许在Java中使用相同的非完全限定名称两次;



我会使

  public interface MyView extends View {


}

只绑定到一个视图(不知道 com.gwtplatform.mvp.client.View MyPresenter.View

  public interface MyView extends MyPresenter.View { 


}

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


}

这样,你不会因为编译器依赖的方式而将接口绑定到错误的类型。 p>

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/GWTP classes.
The class compiles fine with the Eclipse compiler but fails with the javac compiler (Maven).

//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 following error:

cannot find symbol symbol: class View

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

I have other classes which look the same and work fine.
The weird thing is that if I change the order of the imports or I specify the exact package of the View interface 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 cyclic inheritance problem between classes which refer to inner classes (worked in eclipse but didn't in javac). However I am not sure if that is the same problem.

解决方案

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.

这篇关于为什么这个代码用eclipse编译器编译而不是用javac(maven)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆