public class ComparatorTypesVisitor extends java.lang.Object implements TypesVisitor
isCompatible() before
calling isMoreSpecific() as the later always assume compatible hierarchies.
For example, ArrayList<String> is more specific then List<Integer>, but not compatible.
Note that specificity is not the same as assignability. For example List is assignable to
List<? extends String>, but later is more specific (actually). Other example is unknown types:
T<String, Object> is assignable to T<String, String>, but later is more specific
(contains more type information).
TypesWalker| Constructor and Description |
|---|
ComparatorTypesVisitor() |
| 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 |
isCompatible() |
boolean |
isMoreSpecific() |
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 isMoreSpecific()
public boolean isCompatible()