Package org.jvnet.hk2.config
Annotation Type DuckTyped
-
@Retention(RUNTIME) @Target(METHOD) @Documented public @interface DuckTyped
Indicates that this method onConfigBeanProxy
is a duck-typed method that are implemented by the static method on the nested staticDuck
class.Usage
Often it's convenient if one can define some convenience methods on the config bean proxy. This mechanism allows you to do that by putting this annotation on a convenience method, then write the nested static
Duck
class and places the actual implementation there.interface MyConfigBean extends ConfigBeanProxy { @Element List<Property> getProperties(); <DuckTyped String getPropertyValue(String name); class Duck { public static String getPropertyValue(MyConfigBean me, String name) { for( Property p : me.getProperties() ) if(p.getName().equals(name)) return p.getValue(); return null; } } }
The invocation of the getPropertyValue above will cause HK2 to in turn invoke the corresponding static method on
Duck
, where the first argument will be the originalthis
value.- Author:
- Kohsuke Kawaguchi
- See Also:
ConfigBeanProxy