Java Annotations interview questions
Annotation Processors, Custom Annotations, Retention Policies
73 questions with answers and explanations · 73 flashcards
Questions (page 2 of 2)
- How would you explain a key purpose of using MethodHandles in a Java interview?Multiple choiceHard
- Which annotation in Java specifies that the annotated element should be documented by Javadoc and similar tools?Multiple choiceEasy
- What role does the Method.invoke() function play in Java reflection?Multiple choiceMedium
- How would you explain a potential risk of generating code at compile-time using annotation processors in an interview?Multiple choiceHard
- What method would you use to dynamically call a method annotated with a custom annotation at runtime?Multiple choiceMedium
- Which method is used to load a class dynamically at runtime in Java?Multiple choiceEasy
- How does Lombok help reduce boilerplate code in Java?Multiple choiceMedium
- In the context of annotation processing, why might you use RetentionPolicy.SOURCE?Multiple choiceHard
- In a mini-framework using reflection, what is a key advantage of using annotations over configuration files?Multiple choiceHard
- Which annotation property must be specified to make an annotation available at runtime?Multiple choiceMedium
- Why is it important for annotations used in a Spring Boot REST controller to have RetentionPolicy.RUNTIME?Multiple choiceMedium
- Why do teams use a @Retention annotation in custom annotations in production code?Multiple choiceEasy
- Why might you use MethodHandles instead of reflection for method invocation in Java?Multiple choiceHard
- Which of the following is NOT a valid target for an annotation?Multiple choiceEasy
- Why can using reflection in Java applications become a problem in production code?Multiple choiceHard
- If an annotation has RetentionPolicy.CLASS, what happens to it during runtime?Multiple choiceEasy
- Which retention policy for annotations if none is specified is the default in Java?Multiple choiceEasy
- Why does setAccessible(true) on a private field when using reflection change runtime behavior?Multiple choiceHard
- Which of the following retention policies does not allow annotations to be accessed during runtime?Multiple choiceEasy
- Why might a Java framework require annotations with RetentionPolicy.RUNTIME when implementing a feature such as dependency injection?Multiple choiceHard
- Which of the following accurately describes the @Inherited annotation?Multiple choiceHard
- Which Java reflection method can be used to inspect the annotations present on a method during runtime?Multiple choiceMedium
- How does Lombok help in reducing boilerplate code for Java classes?Multiple choiceMedium