CodeGym /Kursus Jawa /Multithreading Jawa /Autoboxing (ora bisa diganti)

Autoboxing (ora bisa diganti)

Multithreading Jawa
tingkat , wulangan
kasedhiya
Autoboxing (ora bisa diganti) - 1

"Halo, Amigo!"

"Dina iki aku bakal nyritakake babagan autoboxing . AutoBoxing tegese kanthi otomatis nglebokake barang menyang kothak."

"Sampeyan bakal ngelingi yen Jawa nduweni jinis sing marisi kelas Obyek, uga jinis primitif.

"Banjur kaputusan digawe kanggo nggawe pasangan non-primitif saka saben jinis primitif."

Tipe primitif Mitra non-primitif
bait Byte
cendhak Singkat
int Ongko
dawa dawa
ngambang ngambang
pindho pindho
boolean Boolean
char Watak
kekosongan batal

"Nanging pancen ora trep kanggo ngonversi ing antarane jinis iki kabeh wektu:"

int x = 3;
Integer y = new Integer(x + 1);
int z = y.intValue();

"Utamane nalika nggarap koleksi langsung:"

Tuladha
int[] numbers = new int[10];
ArrayList list = new ArrayList();
for (int i = 0; i < numbers.length; i++)
{
 list.add( new Integer(i));
}

"Mulane pangripta Jawa nemokke "autoboxing" saka jinis primitif lan 'unboxing' kanggo mitra non-primitif."

"Iki cara kerjane:

Apa sampeyan ndeleng Apa pancene kedadeyan
int x = 3;
Integer y = x + 1;
int x = 3;
Integer y = Integer.valueOf(x + 1);
int z = y;
int z = y.intValue();
Boolean b = Boolean.FALSE;
boolean a = b;
Boolean b = Boolean.FALSE;
boolean a = b.booleanValue();
Integer x = null;
int y = x;
Integer x = null; int y = x.intValue(); //Throws an exception

"Iku kabeh prasaja. Sampeyan bisa nemtokake int lan Integer jinis kanggo saben liyane, lan compiler njupuk care saka kabeh liyane."

"Sing trep banget."

"Ya. Nanging ana nuansa sing bakal dakcritakake mengko."

Komentar
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION