Matchers.subclassesOf matches instances of Class but you’re using it to match instances of TypeLiteral, and Class != TypeLiteral
You'll need to provide your own Matcher implementation that works with TypeLiteral like the following example from a comment on the CustomInjections page of the wiki:
import com.google.inject.TypeLiteral;
import com.google.inject.matcher.AbstractMatcher;
import com.google.inject.matcher.Matcher;
/**
* A factory of {@link Matcher}s that can be used in
* {@link AbstractModule}.bindListener(matcher,listener)
* @author ooktay
*/
public class TypeMatchers {
private static class SubClassesOf extends AbstractMatcher<TypeLiteral<?>> {
private final Class<?> baseClass;
private SubClassesOf(Class<?> baseClass) {
this.baseClass = baseClass;
}
@Override
public boolean matches(TypeLiteral<?> t) {
return baseClass.isAssignableFrom( t.getRawType() );
}
}
/**
* Matcher matches all classes that extends, implements or is the same as baseClass
* @param baseClass
* @return Matcher
*/
public static Matcher<TypeLiteral<?>> subclassesOf(Class<?> baseClass) {
return new SubClassesOf(baseClass);
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~