Reputation: 16671
I have the following code. At runtime typeClassz
is java.util.Set
. But the typeClassz instanceof ParameterizedType evaluates to false. For java.util.Set
it goes to else clause. Any ideas ?
final Type typeClassz = methods.get(index).getParameterTypes()[0];
if(typeClassz instanceof ParameterizedType){
final ParameterizedType classType = (ParameterizedType) ((ParameterizedType) typeClassz).getActualTypeArguments()[0];
return mongoTemplate.findOne(query, (Class<?>) classType.getRawType());
}else{
return mongoTemplate.findOne(query, (Class<?>) typeClassz);
}
Upvotes: 2
Views: 63
Reputation: 20598
Method.getParameterTypes()
returns Class<?>[]
, so your typeClassz
can only be a Class<?>
, not a ParameterizedType
.
You should use getGenericParameterTypes()
instead, which returns a Type[]
.
Upvotes: 6