Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet311/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   307   308   309   310   311   312   313   314   ...   341
Bog'liq
Effective Java



ITEM 87: CONSIDER USING A CUSTOM SERIALIZED FORM
347
/**
* Middle name, or null if there is none.
* @serial
*/
private final String middleName;
... // Remainder omitted
}
Logically speaking, a name consists of three strings that represent a last name,
a first name, and a middle name. The instance fields in 
Name
precisely mirror this
logical content. 
Even if you decide that the default serialized form is appropriate, you
often must provide a 
readObject
 method to ensure invariants and security.
In
the case of 
Name
, the 
readObject
method must ensure that the fields 
lastName
and 
firstName
are non-null. This issue is discussed at length in Items 88 and 90.
Note that there are documentation comments on the 
lastName

firstName
,
and 
middleName
fields, even though they are private. That is because these private
fields define a public API, which is the serialized form of the class, and this public
API must be documented. The presence of the 
@serial
tag tells Javadoc to place
this documentation on a special page that documents serialized forms.
Near the opposite end of the spectrum from 
Name
, consider the following
class, which represents a list of strings (ignoring for the moment that you would
probably be better off using one of the standard 
List
implementations):

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   307   308   309   310   311   312   313   314   ...   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