I have an interface (p) and an implementation (imp). If I do the following in code, then the check works:
if (!(imp instanceof p)) {
logger.error(imp.getClass().getName()+
" doesn't satisfy the interface "
+p.getClass().getName());
}
I tried turning it into a callable method as follows:
private boolean checkInterfaceImplementation(Object implemen, Object inter){
return (implemen instanceof inter);
}
which failed.
Then I discovered that inter must be a specific type, and I cannot use a generic object. Then I found out about
"B.class.isAssignableFrom(A.getClass())"
Then I did:
System.out.println("B.class.isAssignableFrom(A
.getClass())");
There was a way out
True
I read more from this question. My question is: "Is this (the second implementation with" .isAssignableFrom ") the preferred or standard way to implement the specified method? Is there a way that this real implementation can cause problems?