How to use subtypes? - overriding and inheriting in Java
inheritance, java, overriding, wildcard
Solution
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) {}
}
Problem
I've got problem in my code in Java. I have four(important) Classes: ``` public class RDOutput extends OutputType public class RDAnalysis extends AnalysisProperties ``` Now 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?