Crisan Raoul
Crisan Raoul

Reputation: 113

How to create a custom annotation for both classes and methods?

I have to create a custom Logged annotation that can be added to both classes and methods. This is what I've done so far but only works for methods...

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Logger {

}

Upvotes: 2

Views: 1065

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533442

Perhaps you intended to add the ElementType.TYPE to the @Target

@Target({ElementType.METHOD, ElementType.TYPE})

Upvotes: 8

Related Questions