UTP 4 Annotation

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

19 Terms

1
New cards

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.

2
New cards

62. When were annotations introduced in Java?

JDK 1.5 as part of JSR-175

3
New cards

64. Which symbol is used to apply an annotation?

@

4
New cards

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.

5
New cards

66. What is the purpose of @Deprecated?

To discourage usage of an obsolete method

6
New cards

67. Which annotation can suppress compiler messages?

@SuppressWarnings

7
New cards

68. What does @FunctionalInterface enforce?

That the annotated interface has only one abstract method

8
New cards

69. What is the role of meta-annotations?

To annotate annotations giving them extended behavior

9
New cards

70. Which meta-annotation specifies where an annotation can be applied?

  • @Target

  • Example:Java

10
New cards

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).

11
New cards

72. Which retention policy keeps annotations only in source code?

SOURCE

12
New cards

73. Which retention policy allows runtime reflection to read an annotation?

RUNTIME

13
New cards

74. What does @Documented achieve?

Indicates that the target annotation should be included in the generated JavaDocs

14
New cards

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?

15
New cards

76. What does @Repeatable allow?

  • Allows stacking multiple same annotations on one target.

  • Requires a container to hold the repeated annotation instances.

16
New cards

77. Which element type allows applying annotations to type usages such as casts or generics?

TYPE_USE

17
New cards

78. Which element type targets class declarations?

TYPE

18
New cards

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

19
New cards

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.

Explore top flashcards

ap gov
Updated 1003d ago
flashcards Flashcards (55)
Repaso de Español 1
Updated 148d ago
flashcards Flashcards (104)
stems list 30
Updated 1016d ago
flashcards Flashcards (25)
bio-chem
Updated 889d ago
flashcards Flashcards (28)
ap gov
Updated 1003d ago
flashcards Flashcards (55)
Repaso de Español 1
Updated 148d ago
flashcards Flashcards (104)
stems list 30
Updated 1016d ago
flashcards Flashcards (25)
bio-chem
Updated 889d ago
flashcards Flashcards (28)