Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet164/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   160   161   162   163   164   165   166   167   ...   341
Bog'liq
Effective Java



ITEM 39: PREFER ANNOTATIONS TO NAMING PATTERNS
181
The declaration for the 
Test
annotation type is itself annotated with
Retention
and 
Target
annotations. Such annotations on annotation type declara-
tions are known as 
meta-annotations
. The 
@Retention(RetentionPolicy.RUN-
TIME)
meta-annotation indicates that 
Test
annotations should be retained at
runtime. Without it, 
Test
annotations would be invisible to the test tool. The
@Target.get(ElementType.METHOD)
meta-annotation indicates that the 
Test
annotation is legal only on method declarations: it cannot be applied to class dec-
larations, field declarations, or other program elements.
The comment before the 
Test
annotation declaration says, “Use only on
parameterless static methods.” It would be nice if the compiler could enforce this,
but it can’t, unless you write an 
annotation processor 
to do so. For more on this
topic, see the documentation for 
javax.annotation.processing
. In the absence
of such an annotation processor, if you put a 
Test
annotation on the declaration of
an instance method or on a method with one or more parameters, the test program
will still compile, leaving it to the testing tool to deal with the problem at runtime.
Here is how the 
Test
annotation looks in practice. It is called a 
marker anno-
tation
because it has no parameters but simply “marks” the annotated element. If
the programmer were to misspell 
Test
or to apply the 
Test
annotation to a pro-
gram element other than a method declaration, the program wouldn’t compile:

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   160   161   162   163   164   165   166   167   ...   341




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish