Annotations Flashcards

1
Q

A form of metadata, provide data about a program that is not part of the program itself.

A

Annotations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the uses of annotations?

A
  • Information for the compiler
  • compile-time and deployment-time processing
  • runtime processing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Annotations basics

A
  • must start with @
  • can include elements
  • if there is only one element
    @SuppressWarnings(“unchecked”)
  • if no elements
    @Override
  • multiple annotations
  • repeating annotations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Annotations can also be applied to the use of types

A

type annotation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Indicates that the marked element is deprecated and should no longer
be used.

A

@Deprecated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When an element is deprecated, it should also be documented using
the Javadoc

A

@deprecated

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Informs the compiler that the element is meant to override an element
declared in a superclass.

Not required, but avoids errors (promotes proper overriding)

A

@Override

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Annotation tells the compiler to suppress specific warnings that it
would otherwise generate

A

@SuppressWarnings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

annotation specifies how the marked annotation is stored

A

@Retention

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

annotation indicates that whenever the specified
annotation is used those elements should be documented using the
Javadoc tool

A

@Documented

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

annotation marks another annotation to restrict what kind of Java elements the annotation can be applied to

A

@Target

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

annotation indicates that the annotation type can be
inherited from the super class

A

@Inherited

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

annotation, indicates that the marked annotation can be applied more than once to the same declaration or type use

A

@Repeatable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

can be used anywhere you use a type

  • class instance creation expressions (new)
  • Casts
  • implements clauses
  • throws clauses.
A

Type Annotation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

ensures that your variable is not set to null

A

@NonNull

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

ensures your number is not negative

A

@NonNegative

15
Q

for your zero division exception

A

@ZeroDivisor

16
Q

stored in a container annotation that is
automatically generated by the Java compiler

A

Repeating annotations