
gentyref - issue #17
Suggestion to avoid the need for UnresolvedTypeVariableException
I'm trying to determine the actual types in Repositories generated by Spring Data Commons 1.3.0.RELEASE. A simplified version of the code looks like this:
public interface CrudRepository<T, ID extends Serializable> extends Repository<T, ID> { ... <S extends T> S save(S entity); ... }
public interface MyRepository implements CrudRepository<MyEntity, Long> { // no methods }
So when I try to do: Method method = CrudRepository.class.getMethod("save", Object.class) GenericTypeReflector.getExactParameterTypes(method, MyRepository.class);
S is not defined and I get the appropriate exception ( UnresolvedTypeVariableException) from:
if (!map.containsKey(type)) { throw new UnresolvedTypeVariableException(tv); }
What if instead of that a wildcard is returned with the proper bounds? Does it make sense? Am I missing some possible cases?
if (!map.containsKey(type)) { Type[] bounds = tv.getBounds(); return new WildcardTypeImpl(map(bounds), new Type[0]); }
I changed it locally and works fine, at least for my usage scenarios.
Anyway, great job!
Status: New
Labels:
Type-Defect
Priority-Medium