public class DuckType
extends java.lang.Object
implements java.lang.reflect.InvocationHandler
This version is the strict DuckType. All methods present in interfaceToImplement must be present on the target object.
Modifier and Type | Class and Description |
---|---|
static interface |
DuckType.Wrapper
Interface DuckType#Wrapper.
|
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
object |
protected java.lang.Class |
objectClass |
Modifier | Constructor and Description |
---|---|
protected |
DuckType(java.lang.Object object) |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj) |
int |
hashCode() |
static java.lang.Object |
implement(java.lang.Class interfaceToImplement,
java.lang.Object object)
Causes object to implement the interfaceToImplement and returns
an instance of the object implementing interfaceToImplement even
if interfaceToImplement was not declared in object.getClass()'s
implements declaration.
|
static boolean |
instanceOf(java.lang.Class intrface,
java.lang.Object object)
Indicates if object is a (DuckType) instace of intrface.
|
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args) |
protected java.lang.Object object
protected java.lang.Class objectClass
public static java.lang.Object implement(java.lang.Class interfaceToImplement, java.lang.Object object)
This works as long as all methods declared in interfaceToImplement are present on object.
interfaceToImplement
- The Java class of the interface to implementobject
- The object to force to implement interfaceToImplementpublic static boolean instanceOf(java.lang.Class intrface, java.lang.Object object)
intrface
- The interface to implementobject
- The object to testpublic java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
invoke
in interface java.lang.reflect.InvocationHandler
java.lang.Throwable
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object