[英]Javac compilation target 1.7 differs from Eclipse Juno compilation JDK 1.7 when infering Generics
I currently have a compilation issue with Gradle using target 1.7 and source 1.7 vs Eclipse Juno using the built-in 1.7 jdk. 我目前在使用目标1.7和源1.7的Gradle与使用内置1.7 jdk的Eclipse Juno方面存在Gradle的编译问题。
I have 5 classes : 我有5节课:
Info.java --> Interface that has no methods (for example) Info.java- >没有方法的接口(例如)
public interface Info { //... }
RealInfo.java --> Interface that extends the Info interface RealInfo.java- >扩展Info接口的接口
public interface RealInfo extends Info { //... }
AbstractManager.java --> Abstract class that has the method " getInfo() " AbstractManager.java- >具有方法“ getInfo() ”的抽象类
public abstract class AbstractManager<I extends Info>
{
public I info;
public I getInfo()
{
return this.info;
}
}
Manager.java --> Interface that has the method " getInfo() " Manager.java- >具有方法“ getInfo() ”的接口
public interface Manager
{
public <I extends Info> I getInfo();
}
DefaultManager.java --> Extends AbstractManager DefaultManager.java- >扩展AbstractManager
public class DefaultManager extends AbstractManager<RealInfo> implements Manager
{
//...
}
If you copy/paste this code into eclipse, everything works fine. 如果将此代码复制/粘贴到eclipse中,则一切正常。 There's no compilation error.
没有编译错误。 However, if I build it with Gradle, using target jdk 1.7, the compiler will not like it :
但是,如果我使用Gradle使用目标jdk 1.7构建它,则编译器将不会喜欢它:
DefaultManager.java:16: error: DefaultManager is not abstract and does not override abstract method <I>getInfo() in Manager
public class DefaultManager extends AbstractManager<RealInfo> implements Manager
^
where I is a type-variable:
I extends Info declared in method <I>getInfo()
Do you have any idea on what could happen there? 您对那里可能发生的事情有任何想法吗?
I've found what Javac doesn't seem to like. 我发现Javac似乎不喜欢什么。
I modified my AbstractManager class to : 我将AbstractManager类修改为:
public abstract class AbstractManager<I extends Info>
{
public I info;
public <I extends Info> I getInfo()
{
return (I) this.info;
}
}
Gradle now accepts this code while compiling with Javac. Gradle现在在使用Javac进行编译时接受此代码。 It's strange though that it cannot properly infer
I
to <I extends Info>
. 很奇怪,虽然它不能正确地推断
I
到<I extends Info>
。 Eclipse's compiler can handle the two syntaxes. Eclipse的编译器可以处理两种语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.