Junior — Middle
Have you created your own annotations for use in your projects?
sobes.tech AI
Answer from AI
Yes, in Java, you can create custom annotations to add metadata to your code, which can then be used during compilation or runtime. This is useful for creating custom checks, configurations, or integrating with frameworks.
Example of creating a simple annotation:
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME) // Annotation is available at runtime
public @interface MyAnnotation {
String value();
}
// Usage:
@MyAnnotation("Example")
public class MyClass {
// ...
}
Such an annotation can later be processed via reflection to implement the desired logic.