| 1 32 package net.sf.retrotranslator.runtime.impl; 33 34 import java.lang.reflect.*; 35 import java.util.Arrays ; 36 37 40 public class WildcardTypeImpl implements WildcardType { 41 42 private static final Type[] DEFAULT_UPPER_BOUND = new Type[]{Object .class}; 43 private static final Type[] DEFAULT_LOWER_BOUND = new Type[0]; 44 45 private boolean isUpperBounds; 46 private LazyValue<TypeDescriptor, Type> bound; 47 48 public WildcardTypeImpl(boolean isUpperBounds, LazyValue<TypeDescriptor, Type> bound) { 49 this.isUpperBounds = isUpperBounds; 50 this.bound = bound; 51 } 52 53 public Type[] getUpperBounds() { 54 return isUpperBounds && bound != null ? new Type[]{bound.get()} : DEFAULT_UPPER_BOUND; 55 } 56 57 public Type[] getLowerBounds() { 58 return isUpperBounds || bound == null ? DEFAULT_LOWER_BOUND : new Type[]{bound.get()}; 59 } 60 61 public int hashCode() { 62 return Arrays.hashCode(getUpperBounds()) ^ Arrays.hashCode(getLowerBounds()); 63 } 64 65 public boolean equals(Object obj) { 66 if (obj instanceof WildcardType) { 67 if (obj == this) return true; 68 WildcardType type = ((WildcardType) obj); 69 return Arrays.equals(getUpperBounds(), type.getUpperBounds()) && 70 Arrays.equals(getLowerBounds(), type.getLowerBounds()); 71 } 72 return false; 73 } 74 75 public String toString() { 76 if (bound == null) return "?"; 77 Type bound = this.bound.get(); 78 return (isUpperBounds ? "? extends " : "? super ") + 79 (bound instanceof Class ? ((Class ) bound).getName() : bound.toString()); 80 } 81 82 } 83 | Popular Tags |