com.infradna.tool.bridge_method_injector
Annotation Type WithBridgeMethods


@Retention(value=CLASS)
@Target(value=METHOD)
@Documented
@Indexed
public @interface WithBridgeMethods

Request that bridge methods of the same name and same arguments be generated with each specified type as the return type. This helps you maintain binary compatibility as you evolve your classes.

For example, if you have the following code:

 @WithBridgeMethods(Foo.class)
 public FooSubType getFoo() { ... }
 

The Maven mojo will insert the following bridge method:

 public Foo getFoo() {
     return getFoo(); // invokevirtual to getFoo() that returns FooSubType
 }
 

In some cases, it's necessary to widen the return type of a method, but in a way that legacy calls would still return instances of the original type. In this case, add castRequired=true to the annotation. For example, if you have the following code:

 @WithBridgeMethods(value=FooSubType.class, castRequired=true)
 public <T extends Foo> createFoo(Class<T> clazz) {
   return clazz.newInstance();
 }
 

The Maven mojo will insert the following bridge method:

 public FooSubType createFoo(Class clazz) {
   return (FooSubType) createFoo(clazz); // invokeVirtual to createFoo that returns Foo
 }
 

Author:
Kohsuke Kawaguchi

Required Element Summary
 Class<?>[] value
          Specifies the return types.
 
Optional Element Summary
 boolean castRequired
          Specifies whether the injected bridge methods should perform a cast prior to returning.
 

Element Detail

value

public abstract Class<?>[] value
Specifies the return types. These types must be assignable to the actual method return type, or castRequired() should be set to true.

castRequired

public abstract boolean castRequired
Specifies whether the injected bridge methods should perform a cast prior to returning. Only set this to true when it is known that calls to the bridge methods will in fact return types assignable to the actual method return type, even though declared return types are not assignable to the actual method return type.

Since:
1.4
Default:
false


Copyright © 2010. All Rights Reserved.