作者handsomecrow (嗯..一切随他去吧.)
看板java
标题Re: [问题] JAVA技巧 (the transient Keyword)
时间Thu Jun 1 17:53:54 2006
不好意思 我看下来还是不太理解
由於我在写network program 有用到ObjectOutputStream
里面就牵涉到Serializable的问题
在q大给的网页中(
http://0rz.net/1b1s0) 一开始写着
A Bean persists by having its properties, fields, and state information
saved and restored to and from storage. The mechanism that makes persistence
possible is called serialization.
所以Serializable是指 Object在作存取时的一种机制吗?
ex:ObjectOutputStream的writeObject
以下是api中ObjectOutputStream的一段文字
The default serialization mechanism for an object writes the class of the
object,the class signature, and the values of all non-transient and
non-static fields.
就是说除了 加上transient关键字 以及 static field以外的东西都会被输出到串流里面
请问一下是这个意思吗?
同样在ObjectOutputStream的api网页中写到
Only objects that support the java.io.Serializable interface can be written
to streams.
那这样它的范例
FileOutputStream fos = new FileOutputStream("t.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeInt(12345);
oos.writeObject("Today");
oos.writeObject(new Date());
oos.close();
中的 Integer, String Date 其实都是有 implement serializable了?
以上是我的几个问题 麻烦各位了 感恩<(_ _)>
--
中文书是什麽..可以吃吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.134.40.163