@Test public void testIdentityEquals() { Feature feature = createFeature(); FeatureInfo featureInfo1 = AnnotationHandler.create(FeatureInfo.class, feature); FeatureInfo featureInfo2 = AnnotationHandler.create(FeatureInfo.class, feature); Assert.assertFalse(featureInfo1 == featureInfo2); Assert.assertEquals(featureInfo1, featureInfo2); }
@SuppressWarnings("unchecked") public static <T extends Annotation> T create(Class<T> annotationType, Object bean) { return (T) Proxy.newProxyInstance(annotationType.getClassLoader(), new Class<?>[]{annotationType}, new AnnotationHandler(annotationType, bean)); }
AnnotationHandler implements InvocationHandler { @SuppressWarnings("unchecked") public static <T extends Annotation> T create(Class<T> annotationType, Object bean) { return (T) Proxy.newProxyInstance(annotationType.getClassLoader(), new Class<?>[]{annotationType}, new AnnotationHandler(annotationType, bean)); } }
AnnotationHandler implements InvocationHandler { @SuppressWarnings("unchecked") public static <T extends Annotation> T create(Class<T> annotationType, Object bean) { return (T) Proxy.newProxyInstance(annotationType.getClassLoader(), new Class<?>[]{annotationType}, new AnnotationHandler(annotationType, bean)); } private  AnnotationHandler(Class<? extends Annotation> annotationType, Object bean); }
AnnotationHandler implements InvocationHandler { @SuppressWarnings("unchecked") public static <T extends Annotation> T create(Class<T> annotationType, Object bean) { return (T) Proxy.newProxyInstance(annotationType.getClassLoader(), new Class<?>[]{annotationType}, new AnnotationHandler(annotationType, bean)); } private  AnnotationHandler(Class<? extends Annotation> annotationType, Object bean); @SuppressWarnings("unchecked") static T create(Class<T> annotationType, Object bean); @Override Object invoke(Object proxy, Method method, Object[] args); boolean annotationEquals(Object proxy, Object other); int annotationHashCode(Object proxy); String annotationToString(Object proxy); }
AnnotationHandler implements InvocationHandler { @SuppressWarnings("unchecked") public static <T extends Annotation> T create(Class<T> annotationType, Object bean) { return (T) Proxy.newProxyInstance(annotationType.getClassLoader(), new Class<?>[]{annotationType}, new AnnotationHandler(annotationType, bean)); } private  AnnotationHandler(Class<? extends Annotation> annotationType, Object bean); @SuppressWarnings("unchecked") static T create(Class<T> annotationType, Object bean); @Override Object invoke(Object proxy, Method method, Object[] args); boolean annotationEquals(Object proxy, Object other); int annotationHashCode(Object proxy); String annotationToString(Object proxy);  }