I have an interface (p) and an implementation (imp). If I do the following in the code, then the check works:
if (!(imp instanceof p)) {
logger.error(imp.getClass().getName()+
" doesn't satisfy the interface "
+p.getClass().getName());
}
I tried to make it into a callable method as follows:
private boolean checkInterfaceImplementation(Object implemen, Object inter){
return (implemen instanceof inter);
}
which failed.
Then I found that inter needs to 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())");
The output was
true
I read up more from this question. My question is "Is this (the second implementation with ".isAssignableFrom") the preferred or standard way to implement said method? Is there any way that this present implementation can create problems?