1 8 15 21 package jfun.yan; 22 23 import jfun.yan.function.Function; 24 25 26 32 final class ConstructorFunction<T> implements Function<T> { 33 public boolean isConcrete(){ 34 return true; 35 } 36 public T call(Object [] args) 37 throws Throwable { 38 try{ 39 return (T)ctor.getConstructor().newInstance(args); 40 } 41 catch(java.lang.reflect.InvocationTargetException e){ 42 throw Utils.wrapInvocationException(e); 43 } 44 } 45 public Class [] getParameterTypes() { 46 return ctor.getConstructor().getParameterTypes(); 47 } 48 public Class <T> getReturnType() { 49 return ctor.getConstructor().getDeclaringClass(); 50 } 51 52 ConstructorFunction(final java.lang.reflect.Constructor <T> ctor) { 53 this.ctor = new jfun.util.SerializableConstructor(ctor); 54 } 55 private final jfun.util.SerializableConstructor ctor; 56 75 public boolean equals(Object other) { 76 if(other instanceof ConstructorFunction){ 77 final ConstructorFunction m2 = (ConstructorFunction)other; 78 return ctor.equals(m2.ctor); 79 } 80 else return false; 81 } 82 public String getName() { 83 return ctor.getConstructor().getName(); 84 } 85 public int hashCode() { 86 return ctor.hashCode(); 87 } 88 public String toString() { 89 return ctor.toString(); 90 } 91 } 92 | Popular Tags |