如果实现了具有泛型参数的方法的接口,则Eclipse会抱怨名称冲突 [英] Eclipse complains about name clash if an interface with a method having a generic argument is implemented

查看:279
本文介绍了如果实现了具有泛型参数的方法的接口,则Eclipse会抱怨名称冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有关于Java泛型的stackoverflow有一些讨论,但是我太愚蠢地无法解决这个具体问题。我已经在项目中定义了一个接口,并在另一个接口中实现。他们在不同的包装。代替实现该方法,编译器在某些工作区中抱怨:

There are already some discussions here on stackoverflow about Java generics, but I am too stupid to solve this specific question. I have defined an interface in a project, and its implementation in another one. They are in different packages. Instead of implementing the method, the compiler complains in some workspaces:

名称冲突:SuperDuperHighlightable类型的方法突出显示(EnumSet,int,int)具有与突出显示相同的擦除(EnumSet,int,int)类型为IHighlightable但不覆盖它

Name clash: The method highlight(EnumSet, int, int) of type SuperDuperHighlightable has the same erasure as highlight(EnumSet, int, int) of type IHighlightable but does not override it

相同的代码不会在其他工作空间中抱怨,我找不到相关的差异。所有项目和工作区都使用JRE SE 1.5。

The same code does not complain in other workspaces, and I cannot find the relevant differences. All projects and workspaces use JRE SE 1.5.

HighlightingStyle.java

HighlightingStyle.java

package org.my.api;

public enum HighlightingStyle {
 NONE, FIELD, SELECTION, TEST
}

IHighlightable.java

IHighlightable.java

package org.my.api;

import java.util.EnumSet;
import javax.swing.text.BadLocationException;

public interface IHighlightable {
   void highlight(EnumSet<HighlightingStyle> style, int start, int length)
     throws BadLocationException, IllegalArgumentException;
}

实施:

package org.my.impl;

import java.util.EnumSet;
import javax.swing.text.BadLocationException;
import org.my.api.HighlightingStyle;
import org.my.api.IHighlightable;

public class SuperDuperHighlightable implements IHighlightable {

 public void highlight(EnumSet<HighlightingStyle> styleSet, int start, int length)
   throws BadLocationException, IllegalArgumentException {
  for (HighlightingStyle style : styleSet) {
   DoSomething(style, start, length);
  }
 }

 private void DoSomething(HighlightingStyle style, int start, int length) {
  // TODO Auto-generated method stub

 }

}

如果这是一个源代码问题,工作空间问题或Eclipse的一些问题?

Do you have any insights if this is a source-code problem, a workspace problem, or some problem with Eclipse?

推荐答案

没有解决方案,但是一些提示和测试:

No solution yet, but a few tips and tests:


  1. 清理工作空间中的所有项目,这有助于基于eclipse的问题

  2. 确保,你只有在类文件'HighlightingStyle'。也许,实现从不同的源/类加载器获取HighlightingStyle。也许在类路径上有一个包含枚举和/或接口的库

  3. 重命名枚举并检查,如果重构在接口和实现中更改名称。

希望有助于解决您的问题。

Hope it helps to solve your issue..

编辑

Edit

没有得到正确的,它在一些工作区中工作。所以我确定,这是一个工作区配置问题,甚至是一个bug。在这一点上,我个人不会继续修复这个问题,只是将所有项目压缩成一个档案,移动或重命名整个工作区,创建一个新的(同名,原始位置)并导入所有归档项目。如果可以的话,删除已移动或重命名的工作区。

Didn't get correctly, that it works in some workspaces. So I'm sure, this is a workspace configuration issue or maybe even a bug. At this point, I personally would not continue fixing that problem but just zip up all projects into a single archive, move or rename the entire workspace, create a new one (same name, original location) and import all archived projects. If it's OK, delete the moved or renamed workspace.

当然,您松开了工作区设置,我无法确定,如果这是您的案例中的问题。我曾经在某些场合(我有一个丑化的问题与颠覆和汞的插件....),这很容易。

Sure, you loose your workspace settings, and I can't tell, if this is a problem in your case. I did it before on some occasions (I had an ugly issue with subversion and mercurial plugins....) and it's pretty easy.

这篇关于如果实现了具有泛型参数的方法的接口,则Eclipse会抱怨名称冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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