1/18
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
61. What is an annotation in Java?
It is a type of syntactic metadata that can be added to classes, methods, fields, parameters, constructors, local variables, packages, type parameters, and (since Java 8) types themselves.
62. When were annotations introduced in Java?
JDK 1.5 as part of JSR-175
64. Which symbol is used to apply an annotation?
@
65. What does the @Override annotation indicate?
A method being overridden, thus its implementation is redefined in a subclass of some parent class or it states an implementation of some interface's method.
66. What is the purpose of @Deprecated?
To discourage usage of an obsolete method
67. Which annotation can suppress compiler messages?
@SuppressWarnings
68. What does @FunctionalInterface enforce?
That the annotated interface has only one abstract method
69. What is the role of meta-annotations?
To annotate annotations giving them extended behavior
70. Which meta-annotation specifies where an annotation can be applied?
@Target
Example:Java
71. What does @Retention determine?
The stage when the annotation is visible for the compiler.
It is implemented via an enum RetentionPolicy:
RetentionPolicy.SOURCE: Kept only in source code (discarded by the compiler).
RetentionPolicy.CLASS: Kept in the compiled .class file but ignored at runtime.
RetentionPolicy.RUNTIME: Kept at runtime, so it can be read via reflection (most common for frameworks).
72. Which retention policy keeps annotations only in source code?
SOURCE
73. Which retention policy allows runtime reflection to read an annotation?
RUNTIME
74. What does @Documented achieve?
Indicates that the target annotation should be included in the generated JavaDocs
75. What does @Inherited enable?
Implements a feature where all subclasses of the annotated class will inherit the annotation marked with @Inherited76. What does @Repeatable allow?
76. What does @Repeatable allow?
Allows stacking multiple same annotations on one target.
Requires a container to hold the repeated annotation instances.
77. Which element type allows applying annotations to type usages such as casts or generics?
TYPE_USE
78. Which element type targets class declarations?
TYPE
79. What is a recommended best practice when designing custom annotations?
Give them meaningful names
Provide default values if possible
Document them with JavaDoc
Choose appropriate retention policy
Specify @Target
Keep them simple
80. Why should annotations be kept simple?
To ensure readability and maintainability of code.
Complex logic can be enforced in function implementations and other code.