ConstantTransformer
类是Transformer
接口的实现类,其中ConstantTransformer
类重写了接口类的transformer
方法
public class ClosureTransformer implements Transformer, Serializable {
private static final long serialVersionUID = 478466901448617286L;
private final Closure iClosure;
public static Transformer getInstance(Closure closure) {
if (closure == null) {
throw new IllegalArgumentException("Closure must not be null");
} else {
return new ClosureTransformer(closure);
}
}
public ClosureTransformer(Closure closure) {
this.iClosure = closure;
}
public Object transform(Object input) {
this.iClosure.execute(input);
return input;
}
public Closure getClosure() {
return this.iClosure;
}
}
通过ConstantTransformer
类的transform
方法获取一个对象类型,如transform
参数是Runtime.class
时,调用ConstantTransformer
类的transform
方法,执行后返回java.lang.Runtime
类