This content has been marked as final.
Show 2 replies
-
1. Re: Adding MetaData.isAnnotationPresent(String annotationTyp
adrian.brock Feb 13, 2008 6:28 AM (in response to kabirkhan)It already exists:
/** * Is the metadata present * * @param name the name of the meta data * @return true when the metadata is present */ boolean isMetaDataPresent(String name);
If you're not going to check whether the name is really an annotation class
then they are the same thing.
Of course, you might want to implement it like this, just to make doubly sure :-)public boolean isAnnotationPresent(String name) { Object test = getMetaData(name); return test != null && (test instanceof Annotation); }
But such a non-annotation using the name of annotation class would break
the assumption of how the annotation stuff works in the metadata. :-) -
2. Re: Adding MetaData.isAnnotationPresent(String annotationTyp
adrian.brock Feb 13, 2008 7:42 AM (in response to kabirkhan)Of course, the above was pseudo code.
What I really mean is that you don't need to change the MetaData api,
you could just have a static helper method (real code):public static boolean isAnnotationPresent(MetaData metaData, String name) { if (metaData == null) throw new IllegalArgumentException("Null metadata"); Object test = metaData.getMetaData(name); return test != null && (test instanceof Annotation); }