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

isInstanceOf

open static fun isInstanceOf(type: Class<*>, @Nullable obj: Any, message: String): Unit

Assert that the provided object is an instance of the provided class.

Assert.instanceOf(Foo.class, foo, "Foo expected");

Parameters

type - the type to check against

obj - the object 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 object's type will be appended. In any other case, a ":" with a space and the name of the offending object's type will be appended.

Exceptions

IllegalArgumentException - if the object is not an instance of type

open static fun isInstanceOf(type: Class<*>, @Nullable obj: Any, messageSupplier: Supplier<String>): Unit

Assert that the provided object is an instance of the provided class.

 Assert.instanceOf(Foo.class, foo, () -> "Processing " + Foo.class.getSimpleName() + ":"); 

Parameters

type - the type to check against

obj - the object to check

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

Exceptions

IllegalArgumentException - if the object is not an instance of type

Since
5.0

open static fun isInstanceOf(type: Class<*>, @Nullable obj: Any): Unit

Assert that the provided object is an instance of the provided class.

Assert.instanceOf(Foo.class, foo);

Parameters

type - the type to check against

obj - the object to check

Exceptions

IllegalArgumentException - if the object is not an instance of type