Thank you Jean for your advice this is what is working for me :
/**
* Our custom guice Matcher classes
* @author Marcin Misiewicz
*
*/
public final class Matchers {
public static Matcher<? super TypeLiteral<?>> subtypeOf(
final Class<?> superclass) {
return new SubtypeOf(TypeLiteral.get(superclass));
}
public static Matcher<? super TypeLiteral<?>> subtypeOf(
final TypeLiteral<?> supertype) {
return new SubtypeOf(supertype);
}
private static class SubtypeOf extends AbstractMatcher<TypeLiteral<?
>>
implements Serializable {
private static final long serialVersionUID = 1239939466206498961L;
private final TypeLiteral<?> supertype;
/**
* @param superType
*/
public SubtypeOf(TypeLiteral<?> superType) {
super();
this.supertype = checkNotNull(superType, "supertype");
}
/*
* (non-Javadoc)
*
* @see com.google.inject.matcher.Matcher#matches(java.lang.Object)
*/
@Override
public boolean matches(TypeLiteral<?> subtype) {
return (subtype.equals(supertype) ||
supertype.getRawType().isAssignableFrom(subtype.getRawType()));
}
@Override
public boolean equals(Object other) {
return other instanceof SubtypeOf
&& ((SubtypeOf) other).supertype.equals(supertype);
}
@Override
public int hashCode() {
return 37 * supertype.hashCode();
}
@Override
public String toString() {
return "subtypeOf(" + supertype.getRawType() + ".class)";
}
}
}
You have saved me a lot of time and helped to better understand
TypeLiterals ;)
Marcin Misiewicz
On 5 Lis, 01:00, Jean-Francois Poilpret <
jfpoilp...@yahoo.fr> wrote:
> Marcin Misiewicz wrote:
> > Hi
>
> > I'm implementing custom injection thanks to
> >
http://code.google.com/docreader/#p=google-guice&s=google-guice&t=Cus....