Agreed. Right now, internally we ( my job ) use separate literal classes.

On Wed, Jul 10, 2013 at 11:05 AM, Pete Muir <[email protected]> wrote:

> I think as we can only do this for annotations in our control, it's less
> appealing, as we then end up with both patterns in use.
>
> On 10 Jul 2013, at 12:23, Hugh Nguyen <[email protected]> wrote:
>
> > Hi fellow developers,
> >
> > Instead of creating a whole separate class SomeAnnotationLiteteral and
> put
> > it in some separate .literal package, do you think we should embed the
> > literal inside the annotation class itself?
> >
> > For example:
> >
> >
> > @Qualifier
> > @Target({ FIELD, PARAMETER })
> > @Retention(RUNTIME)
> > public @interface RenderResponse {
> >
> >    @SuppressWarnings("serial")
> >    public static final AnnotationLiteral<RenderResponse> LITERAL = new
> > AnnotationLiteral<RenderResponse>() {
> >    };
> > }
> >
> >
> > And when you use this literal as RenderResponse.LITERAL, you even have it
> > highlighted properly as an annotation by the IDE.
> >
> >
> > For cases where the annotation has attributes, we could declare it like
> > this:
> >
> >
> > @Qualifier
> > @Target({ FIELD, PARAMETER })
> > @Retention(RUNTIME)
> > public @interface View {
> >    String value() default "";
> >
> >    // need to suppress "all" to remove warning about implementing an
> > Annotation.
> >    @SuppressWarnings("all")
> >    public static class LITERAL extends AnnotationLiteral<View> implements
> > View {
> >        private String value = "";
> >
> >        @Override
> >        public String value() {
> >            return this.value;
> >        }
> >
> >        public Literal(final String value) {
> >            if (value != null) {
> >                this.value = value;
> >            }
> >        }
> >    }
> > }
> >
> >
> > And we use it as: new View.LITERAL("someViewId"). This is also
> highlighted
> > by the IDE.
> >
> >
> > Of course this is only applicable for those Annotation that's in our
> > control.
> >
> > What do you think?
> >
> >
> > --
> > Regards,
> > Hugh
>
>

Reply via email to