[type-annos-observers] AnnotatedWildcardType upper bounds question
elena votchennikova
elena.votchennikova at oracle.com
Fri Jul 18 13:26:13 UTC 2014
Hi all,
I have a question regarding AnnotatedWildcardType upper bounds.
Could you please look at the following example.
Minimized test:
-------------------------------------------------------------------------------
public class Test {
public Test(List<? super String> p) {}
public static void main(String[] args) throws NoSuchMethodException {
Constructor constructor = Test.class.getConstructor(List.class);
AnnotatedParameterizedType at = (AnnotatedParameterizedType)
constructor.getAnnotatedParameterTypes()[0];
System.out.println(((AnnotatedWildcardType)
at.getAnnotatedActualTypeArguments()[0]).getAnnotatedUpperBounds().length);
ParameterizedType t = (ParameterizedType)
constructor.getGenericParameterTypes()[0];
System.out.println(((WildcardType)
t.getActualTypeArguments()[0]).getUpperBounds().length);
}
}
-------------------------------------------------------------------------------
Output (tested with jdk8b132):
-------------------------------------------------------------------------------
0
1
-------------------------------------------------------------------------------
As I understand output should be:
-------------------------------------------------------------------------------
1
1
-------------------------------------------------------------------------------
According to the spec for j.l.r.WildcardType:
"Note that if no upper bound is explicitly declared, the upper bound
is|Object.|"
And looks like this should be also true for j.l.r.AnnotatedWildcardType.
Or I'm mistaken?
By the way, if we have wildcard without definition of lower and upper
bounds, wildcardAnnotatedType.getAnnotatedUpperBounds().length will
return 1.
Thank you,
Elena
More information about the type-annotations-spec-observers
mailing list