Cov txheej txheem:

Vim li cas peb ntxiv serialVersionUID?
Vim li cas peb ntxiv serialVersionUID?

Video: Vim li cas peb ntxiv serialVersionUID?

Video: Vim li cas peb ntxiv serialVersionUID?
Video: Vim Li Cas Yuav Tsum Txhaj Tshuaj Yog Tias Tseem Tau Txhab Ntxiv Thiab? (Hmong) 2024, Kaum ib hlis
Anonim

Vim li cas thiaj li peb siv SerialVersionUID : SerialVersionUID yog siv los xyuas kom meej tias thaum lub sij hawm deserialization tib chav kawm (uas tau siv thaum lub sij hawm serialize txheej txheem) yog loaded. Serialization: Thaum lub sij hawm serialization, nrog rau txhua yam khoom xa tawm sab JVM yuav txuag tus cim cim tshwj xeeb.

Tsis tas li ntawd, vim li cas peb thiaj siv serialVersionUID?

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, kom ntseeg tau tias cov chav kawm loaded yog sib xws nrog cov khoom serialized. Yog tias tsis pom qhov sib txuam hauv chav kawm, ib qho InvalidClassException raug pov tseg.

Ib sab saum toj no, puas xav tau serialVersionUID? 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.

Ib sab ntawm qhov no, 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.

Dab tsi yog txhais los ntawm serialVersionUID?

Java: Yuav ua li cas tsim serialVersionUID

  1. serialver hais kom ua. JDK muaj kev tsim hauv cov lus txib hu ua "serialver" los tsim cov serialVersionUID tau.
  2. Siv Eclispe IDE. Yog tias koj tab tom siv dab noj hnub, txav koj tus nas hla cov chav kawm serialization.
  3. Txhua yam koj xav tau. Tsuas yog qhia koj tus kheej serialVersionUID, muab tus lej thiab ntxiv rau "L" tom qab.

Pom zoo: