I bumped recently (twice) at following problem - is it possible to find on classpath specific implementation of generic interface? To visualize this please consider these snippets of code:
public interface Cleaner<T extends Room> {}
public class KitchenCleaner implements Cleaner<Kitchen> {}
public class BathroomCleaner implements Cleaner<Bathroom> {}
Now - Is it possible to have a following method ?:
public static <T extends Room> findCleanerServiceForRoomType(T room) {
return ???
}
returning KitchenCleaner for Kitchen class and BathroomCleaner for Bathroom class? Of course I would like to have it extensible so that when new Room and Service type is added this method still works... So no switches or ifs :)