1 8 9 15 package jfun.yan; 16 17 import jfun.yan.function.Function; 18 19 25 final class ArrayConstructorFunction<T> implements Function<T> { 26 private final Class <T> array_type; 27 public boolean isConcrete(){ 28 return true; 29 } 30 ArrayConstructorFunction(final Class <T> array_type) { 31 this.array_type = array_type; 32 } 33 private static final Class [] ptypes = new Class []{int.class}; 34 public T call(Object [] args) throws Throwable { 35 return (T)java.lang.reflect.Array.newInstance(array_type.getComponentType(), 36 ((Integer )args[0]).intValue()); 37 } 38 public Class [] getParameterTypes() { 39 return ptypes; 40 } 41 public Class <T> getReturnType() { 42 return array_type; 43 } 44 public boolean equals(Object obj) { 45 if(obj instanceof ArrayConstructorFunction){ 46 final ArrayConstructorFunction other = (ArrayConstructorFunction)obj; 47 return array_type.equals(other.array_type); 48 } 49 else return false; 50 } 51 public int hashCode() { 52 return array_type.hashCode(); 53 } 54 public String toString() { 55 return jfun.util.Misc.getTypeName(array_type)+".new"; 56 } 57 public String getName(){ 58 return "new[]"; 59 } 60 } 61 | Popular Tags |