Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet248/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   244   245   246   247   248   249   250   251   ...   341
Bog'liq
Effective Java



CHAPTER 9
GENERAL PROGRAMMING
276
Item 62: Avoid strings where other types are more appropriate
Strings are designed to represent text, and they do a fine job of it. Because strings
are so common and so well supported by the language, there is a natural tendency
to use strings for purposes other than those for which they were designed. This
item discusses a few things that you shouldn’t do with strings.
Strings are poor substitutes for other value types.
When a piece of data
comes into a program from a file, from the network, or from keyboard input, it is
often in string form. There is a natural tendency to leave it that way, but this ten-
dency is justified only if the data really is textual in nature. If it’s numeric, it
should be translated into the appropriate numeric type, such as 
int

float
, or
BigInteger
. If it’s the answer to a yes-or-no question, it should be translated into
an appropriate enum type or a 
boolean
. More generally, if there’s an appropriate
value type, whether primitive or object reference, you should use it; if there isn’t,
you should write one. While this advice may seem obvious, it is often violated.

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   244   245   246   247   248   249   250   251   ...   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