ConstantTransformer类是Transformer接口的实现类,其中ConstantTransformer类重写了接口类的transformer方法

    1. public class ClosureTransformer implements Transformer, Serializable {
    2. private static final long serialVersionUID = 478466901448617286L;
    3. private final Closure iClosure;
    4. public static Transformer getInstance(Closure closure) {
    5. if (closure == null) {
    6. throw new IllegalArgumentException("Closure must not be null");
    7. } else {
    8. return new ClosureTransformer(closure);
    9. }
    10. }
    11. public ClosureTransformer(Closure closure) {
    12. this.iClosure = closure;
    13. }
    14. public Object transform(Object input) {
    15. this.iClosure.execute(input);
    16. return input;
    17. }
    18. public Closure getClosure() {
    19. return this.iClosure;
    20. }
    21. }

    通过ConstantTransformer类的transform方法获取一个对象类型,如transform参数是Runtime.class时,调用ConstantTransformer类的transform方法,执行后返回java.lang.Runtime