Class DuckType
- java.lang.Object
-
- org.eclipse.nebula.widgets.compositetable.internal.DuckType
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
- Direct Known Subclasses:
RelaxedDuckType
public class DuckType extends java.lang.Object implements java.lang.reflect.InvocationHandlerDuckType. Implements Duck Typing for Java. ("If it walks like a duck, quacks like a duck, it..."). Essentially allows programs to treat objects from separate hierarchies as if they were designed with common interfaces as long as they adhere to common naming conventions.This version is the strict DuckType. All methods present in interfaceToImplement must be present on the target object.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceDuckType.WrapperInterface DuckType#Wrapper.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Objectobjectprotected java.lang.ClassobjectClass
-
Constructor Summary
Constructors Modifier Constructor Description protectedDuckType(java.lang.Object object)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)inthashCode()static java.lang.Objectimplement(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 booleaninstanceOf(java.lang.Class intrface, java.lang.Object object)Indicates if object is a (DuckType) instace of intrface.java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
-
-
-
Method Detail
-
implement
public 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.This works as long as all methods declared in interfaceToImplement are present on object.
- Parameters:
interfaceToImplement- The Java class of the interface to implementobject- The object to force to implement interfaceToImplement- Returns:
- object, but now implementing interfaceToImplement
-
instanceOf
public static boolean instanceOf(java.lang.Class intrface, java.lang.Object object)Indicates if object is a (DuckType) instace of intrface. That is, is every method in intrface present on object.- Parameters:
intrface- The interface to implementobject- The object to test- Returns:
- true if every method in intrface is present on object. false otherwise
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable- Specified by:
invokein interfacejava.lang.reflect.InvocationHandler- Throws:
java.lang.Throwable
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-