Ob chav kawm puas muaj tib serialVersionUID?
Ob chav kawm puas muaj tib serialVersionUID?

Video: Ob chav kawm puas muaj tib serialVersionUID?

Video: Ob chav kawm puas muaj tib serialVersionUID?
Video: Qhia saib me nyuam hauv plab seb yog tub lo yog ntxhai 2024, Kaum ib hlis
Anonim

Yog, nws muaj peev xwm ua tau ob txawv cov chav kawm tuaj yeem muaj tus tib serialVersionUID tus nqi. Tab sis nyiam siv ib qho tshwj xeeb rau txhua tus chav kawm . Kuj tseem siv 8 txog 10 tus lej ntev dua ib qho tsis yog 1 tus nqi xwb.

Yog li ntawd, serialVersionUID yog dab tsi?

Cias muab, lub serialVersionUID yog tus cim tshwj xeeb rau cov chav kawm Serializable. Qhov no yog siv thaum lub sij hawm deserialization ntawm ib yam khoom, los xyuas kom meej tias cov chav kawm loaded yog sib xws nrog cov khoom serialized.

Ib yam li ntawd, kev siv serialVersionUID 1l yog dab tsi? Cov serialVersionUID yog universal version identifier rau chav kawm Serializable. Deserialization siv tus lej no los xyuas kom meej tias cov chav kawm loaded sib raug raws nraim rau ib qho khoom serialized. Yog tias tsis pom qhov sib tw, ces qhov InvalidClassException raug pov tseg.

Ib yam li ntawd, nws tau nug, puas yog serialVersionUID xav tau?

lub neej ntawd serialVersionUID Kev suav yog qhov nkag siab zoo rau cov ntsiab lus hauv chav kawm uas yuav txawv nyob ntawm kev siv compiler, thiab ua tau yog li ua rau poob siab InvalidClassException s thaum lub sij hawm deserialization. Yog li ntawd, koj yuav tsum tshaj tawm serialVersionUID vim nws ua rau peb tswj tau ntau dua.

Lub luag haujlwm ntawm serialVersionUID yog dab tsi hauv cov txheej txheem serialization?

Thaum serialization , java runtime associates a version number with each serializable chav kawm. Tus lej no hu serialVersionUID , uas yog siv thaum lub sij hawm deserialization los xyuas kom meej tias tus sender thiab receiver ntawm a serialized cov khoom tau thauj cov chav kawm rau cov khoom ntawd uas sib haum nrog kev hwm serialization.

Pom zoo: