public class AssignabilityTypesVisitor extends java.lang.Object implements TypesVisitor
T<String, Object> is assignable to T<String, String> as Object considered as unknown
type and so could be compatible (in opposite way is also assignable as anything is assignable to Object).
Java wildcard rules are generally not honored because at runtime they are meaningless.
List == List<Object> == List<? super Object> == List<? extends Object>. All upper bounds are used for
comparison (multiple upper bounds in wildcard could be from repackaging of generic declaration
T<extends A&B>. Lower bounds are taken into account as: if both have lower bound then
right's type bound must be higher (? extends Number and ? extends Integer). If only left
type is lower bounded wildcard then it is not assignable (except Object).
| Constructor and Description |
|---|
AssignabilityTypesVisitor() |
| Modifier and Type | Method and Description |
|---|---|
void |
incompatibleHierarchy(java.lang.reflect.Type one,
java.lang.reflect.Type two)
Called when synchronous walk is impossible.
|
boolean |
isAssignable() |
boolean |
next(java.lang.reflect.Type one,
java.lang.reflect.Type two)
Method is called for each matching types pair in types hierarchy.
|
public boolean next(java.lang.reflect.Type one,
java.lang.reflect.Type two)
TypesVisitorList<String> and ArrayList<String> will lead to two calls with
List<String>, ArrayList<String> and then String, String. Method may return false
to stop types traversing.
When types are not compatible then TypesVisitor.incompatibleHierarchy(Type, Type) is called instead.
Passed types are always compatible on current level. For example List<String> and List<Integer>
are compatible on class level (assumed as List and List, but on the next level incompatible
type will be notified. Overall two visitor calls will be done: TypesVisitor.next(Type, Type) for lists and
TypesVisitor.incompatibleHierarchy(Type, Type) for list generics.
If one of the types is Object then it will be the last step (no hierarchy incompatibility will be
called as object is compatible with everything - we just can't go further because of not enough information).
next in interface TypesVisitorone - current class in first hierarchytwo - class from second hierarchy, but from the same place (in type tree)public void incompatibleHierarchy(java.lang.reflect.Type one,
java.lang.reflect.Type two)
TypesVisitorincompatibleHierarchy in interface TypesVisitorone - current type from hierarchy one (not root type)two - current type from hierarchy twopublic boolean isAssignable()