Annotations Flashcards

1
Q

Retence anotace - syntax, druhy (3)

A

@Retention(RetentionPolicy.RUNTIME)
source
class
runtime

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

Target anotace - syntax, druhy (11)

A

@Target(ElementType.METHOD, ElementType.FIELD)
annotation_type
field, local_variable, parameter
method, constructor
package, module
type, type_parameter, type_use

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

Dedicnost anotaci

A

Nededi se, ale lze vynutit pomoci @Inherited

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

Anotace v javadocu

A

@Documented - vypise se do javadocu

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

Anotace, ktera se muze opakovat - definice, pouziti

A

@Repeatable(Ann1.class)
public @interface Ann2 { … }

@Ann1({@Ann2, @Ann2})

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

Elementy anotace - jake muzou byt druhy? (5)

A

primitive, String, class, enum
array cehokoli z toho

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

Zapis anotace s retention, target, elementem s a bez hodnoty, array elementem

A

@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.FIELD)
public @interface MyAnnotation {
int field1() default 0;
int field2();
int[] field3;
}

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

Pouziti anotace - zapis hodnot array (1), zapis pro anotaci s jedinym elementem (2)

A

@Ann(element = {“a”, “b”})

@Ann(element = value)
@Ann(value)

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

Deprecation: anotace, javadoc anotace

A

@Deprecated(since=”11”, forRemoval=true)
@deprecated

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

Potlaceni syntax warningu anotaci
castovani
pouziti deprecated metody
pretypovani varargs (heap pollution)

A

@SuppressWarnings(“unchecked”, “deprecation”)
@SafeVarargs + metoda bud private nebo final

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

Reflection - ktere anotace nejdou reflexi zjistit?
anotace tridy (2)
anotace - ziskej typ a elementy

A

source
class.getAnnotations(), getAnnotationsByType(Ann.class)
a.getAnnotationType()
a.jmenoElementu()

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