spring-framework / org.springframework.util / Assert / isAssignable

isAssignable

open static fun isAssignable(superType: Class<*>, @Nullable subType: Class<*>, message: String): Unit

Assert that superType.isAssignableFrom(subType) is true.

Assert.isAssignable(Number.class, myClass, "Number expected");

Parameters

superType - the super type to check against

subType - the sub type to check

message - a message which will be prepended to provide further context. If it is empty or ends in ":" or ";" or "," or ".", a full exception message will be appended. If it ends in a space, the name of the offending sub type will be appended. In any other case, a ":" with a space and the name of the offending sub type will be appended.

Exceptions

IllegalArgumentException - if the classes are not assignable

open static fun isAssignable(superType: Class<*>, @Nullable subType: Class<*>, messageSupplier: Supplier<String>): Unit

Assert that superType.isAssignableFrom(subType) is true.

 Assert.isAssignable(Number.class, myClass, () -> "Processing " + myAttributeName + ":"); 

Parameters

superType - the super type to check against

subType - the sub type to check

messageSupplier - a supplier for the exception message to use if the assertion fails. See #isAssignable(Class, Class, String) for details.

Exceptions

IllegalArgumentException - if the classes are not assignable

Since
5.0

open static fun isAssignable(superType: Class<*>, subType: Class<*>): Unit

Assert that superType.isAssignableFrom(subType) is true.

Assert.isAssignable(Number.class, myClass);

Parameters

superType - the super type to check

subType - the sub type to check

Exceptions

IllegalArgumentException - if the classes are not assignable