/
AnnotationsOnSubclass.java
40 lines (30 loc) · 1.11 KB
/
AnnotationsOnSubclass.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package xyz.mcomella.threadannotationstest;
import android.support.annotation.UiThread;
import android.support.annotation.WorkerThread;
class AnnotationsOnSubclass {
@UiThread
void onUiThread() {}
@UiThread
void onUiThreadUntilOverriden() {}
void annotatedInSubclass() {}
static class ActualSubclass extends AnnotationsOnSubclass {
@Override
void onUiThread() {}
@WorkerThread
@Override
void onUiThreadUntilOverriden() {}
@UiThread
@Override
void annotatedInSubclass() {}
@WorkerThread
void testSubclassMethodAnnotations() {
// The subclass correctly inherits the thread annotation
// even if the annotated method is overridden.
onUiThread(); // correct: displays warning.
// However, the annotation cannot be overridden by the subclass.
onUiThreadUntilOverriden(); // arguable: displays warning.
// But if the annotation was never declared, the subclass can assign one.
annotatedInSubclass(); // correct: displays warning.
}
}
}