public final class ClassType extends java.lang.Object
int
and Integer
are the same
class type. This class is immutable.
The list of additional interfaces is kept normalized, such that no interface is in the list if it already implicitly given (either implemented by the base type or by another interface of the list).
Constructor and Description |
---|
ClassType()
Creates the most general class type, that is of type Object without any
additional interfaces.
|
ClassType(java.lang.Class<?>... classes)
Creates a new class type from a list of "normal" class by either using it
as the base class or adding it to the interface list.
|
ClassType(java.lang.Class<?> clazz)
Creates a new class type from a "normal" class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
java.lang.Class<?> |
getBaseClass()
Returns the base class for this ClassType.
|
UnmodifiableSet<java.lang.Class<?>> |
getInterfaces()
Returns all interfaces implemented by this class type in addition to the
base class.
|
int |
hashCode()
Returns a hash code for this instance based on the base class and the
additional (normalized) interfaces.
|
boolean |
hasInterfaces()
Returns whether this ClassType requires the implementation of interfaces
in addition to the base class.
|
boolean |
implementsInterface(java.lang.Class<?> requiredInterface)
Returns whether the provided interface is implemented by this class type.
|
ClassType |
intersect(ClassType classType)
Intersects the given class type with this type.
|
boolean |
isAssignableFrom(ClassType classType)
Checks if an object of class type
classType could be
assigned to an object of this class type. |
ClassType |
merge(ClassType classType)
Merges the given class type with this type.
|
java.lang.String |
toString() |
public ClassType()
public ClassType(java.lang.Class<?> clazz)
public ClassType(java.lang.Class<?>... classes) throws TypesNotMergableException
TypesNotMergableException
- if the provided classes can not be joined.public ClassType merge(ClassType classType) throws TypesNotMergableException
Merging corresponds to "and" types, i.e. the resulting type will be assignable to each of the input types.
TypesNotMergableException
- if the new type could not be merged in.public ClassType intersect(ClassType classType)
Intersection corresponds to "or" types, i.e. the resulting type will be assignable from each of the input types.
public java.lang.Class<?> getBaseClass()
public boolean hasInterfaces()
public UnmodifiableSet<java.lang.Class<?>> getInterfaces()
public boolean isAssignableFrom(ClassType classType)
classType
could be
assigned to an object of this class type.public boolean implementsInterface(java.lang.Class<?> requiredInterface)
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object