java - How to implement a list of a specific concrete class from the abstract class? -
i have abstract class "actor" , should generate list (arraylist, maybe best option) of 1 of concrete classes implemented, lets use "actor1". there 3 or more concrete classes actor1,2,3... made using factory method , of them must have list of actor1(s) created.
any suggestion?
ok, didn't expected such fast response. well, don't start with, of code this, far:
public abstract class actor implements iactor { protected coordinates coordinates; protected list<actor> actor1; public actor(coordinates coordinates) { this.coordinates = coordinates; //how implemet list? } public coordinates getlocation() { return coordinates; } public void setcoordinates(coordinates coordinates) { this.coordinates = coordinates; }
i make actor generic type bounded itself, , restrict further in concrete subclasses.
public abstract class actor<a extends actor<a>> { public list<a> getactors() { ... } public class actor1 extends actor<actor1> { ...
that way, getactors
actor1
return list<actor1>
.
Comments
Post a Comment