This question already has an answer here:
What is the best way to call a base function on all the implementations of an interface with reflection and fewer lines possible.
public interface BaseClass { public void doSomething();}
public class A implements BaseClass {
@Override
public void doSomething () {
System.out.println("doing Something in A");
}
}
public class B implements BaseClass {
@Override
public void doSomething () {
System.out.println("doing Something in B");
}
}
public class anotherClass {
public static void main(final String[] args) {
// get all the implementations of BaseClass;
// for each implementation call doSomething();
}
}
Aucun commentaire:
Enregistrer un commentaire