我的Java代码存在问题。 我有四个(重要)类:
public class RDOutput extends OutputType public class RDAnalysis extends AnalysisProperties现在我正在尝试在Analysis属性中创建一个方法:
public abstract void display(ArrayList<? extends OutputType> results);主要问题列表,ArrayList中的对象将是OutputType的不同子类型。 在我的课程RDAnalysis中,我尝试进行特定的覆盖:
public void display(ArrayList<RDOutput> results) {但是eclipse说:名称冲突:类型RDAnalysis的方法显示(ArrayList)与AnalysisProperties类型的显示(ArrayList?extends OutputType)具有相同的擦除但不覆盖它
我不熟悉Java技巧,我尝试在文档中搜索,但我找不到任何解决这个问题的方法。 我的问题是:我正在做的那种技巧(抽象的基本类型和最终函数中的扩展)可能在Java中(如果是的话,我该怎么做?)或者我必须做一些枚举来解决这个问题吗?
I've got problem in my code in Java. I have four(important) Classes:
public class RDOutput extends OutputType public class RDAnalysis extends AnalysisPropertiesNow I'm trying to make a method in Analysis properties:
public abstract void display(ArrayList<? extends OutputType> results);The main problem list, the objects in the ArrayList will be different subtypes of OutputType. In my class RDAnalysis I try to make specific overriding:
public void display(ArrayList<RDOutput> results) {but eclipse says: Name clash: The method display(ArrayList) of type RDAnalysis has the same erasure as display(ArrayList? extends OutputType) of type AnalysisProperties but does not override it
I'm not familiar with Java tricks, I tried searching in documentation and I didn't find any solution to this problem. My question is: Is that trick that I'm doing (Basic type in abstract and Extended in final function) possible in Java (if yes, how can I do that?) or do I have to make some enum to solve this?
最满意答案
我建议你在你的类中引入泛型参数,并用它来参数化你的方法:
public abstract class A<T extends OutputType> { public abstract void display(ArrayList<T> results); } public class B extends A<RDOutput> { public void display(ArrayList<RDOutput> results) {} }I suggest you to introduce generic parameter to your class and use it to parametrize your method:
public abstract class A<T extends OutputType> { public abstract void display(ArrayList<T> results); } public class B extends A<RDOutput> { public void display(ArrayList<RDOutput> results) {} }更多推荐
发布评论