Icosmos.class.isInstance(parameterTypes[0])
is exactly equivalent to parameterTypes[0] instanceof Icosmos
, and checks whether the object parameterTypes[0]
is an instance of Icosmos
(which it isn't - it's a java.lang.Class
).
There are two possibilities for what you really need. One would be
Icosmos.class.isAssignableFrom(parameterTypes[0])
which checks whether the class parameterTypes[0]
is assignment-compatible with Icosmos
, i.e. given an x
which is an instance of the class represented by parameterTypes[0]
, would
Icosmos foo = x;
be legal without a cast. This would check that the declared type of the first formal parameter is compatible with Icosmos
.
The second alternative would be
args[0] instanceof Icosmos
which checks the runtime type of the actual argument value rather than the declared type of the formal parameter.