public @interface MyAnnotation {
String value();
}
@MyAnnotation(value = "example")
public class MyClass {
// Class implementation
}
Class<MyClass> clazz = MyClass.class;
MyAnnotation annotation = clazz.getAnnotation(MyAnnotation.class);
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
String value();
}
@MyAnnotation(value = "example")
public class MyClass {
public static void main(String[] args) {
Class<MyClass> clazz = MyClass.class;
MyAnnotation annotation = clazz.getAnnotation(MyAnnotation.class);
}
}
import jakarta.servlet.*;
import jakarta.servlet.http.*;
@WebServlet(name = "MyServlet", urlPatterns = {"/my-servlet"})
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
// Servlet implementation
}
}