يشير Transient إلى أن الخاصية مؤقتة ولن يتم إجراء تسلسل لها.
ما يلي هو عرض توضيحي. تم الإعلان عن الاسم على أنه عابر ولن يتم إجراء تسلسل له.
الحزمة com.zzs.tet;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInput;import java.io.ObjectInputStream;استيراد java.io.ObjectOutput;استيراد java.io.ObjectOutputStream;import java.io.Serializable;public class TransientDemo Implements Serializable{ /** * */private static Final long serialVersionUID = 1L;اسم سلسلة عابرة خاصة; public String getName() {return name ;} public void setName(String name) {this.name = name;} public String getPassword() {return كلمة المرور;} public void setPassword(String كلمة المرور) {this.password = كلمة المرور؛}/** * @param args * @throws IOException * @throws FileNotFoundException * @throws ClassNotFoundException */public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {// TODO طريقة تم إنشاؤها تلقائيًا stubString path="D:"+File.separator+"object.txt";ملف الملف=ملف جديد(مسار);TransientDemo transientDemo=new TransientDemo();transientDemo.setName("name");transientDemo.setPassword("كلمة المرور") ;ObjectOutputput=new ObjectOutputStream(new FileOutputStream(file));output.writeObject(transientDemo);ObjectInput input=new ObjectInputStream(new FileInputStream(file));TransientDemo demo=(TransientDemo )input.readObject();System.out.println(demo.getName()+demo.getPassword());}}نتيجة الإخراج:
كلمة المرور فارغة