一般我们在定义entity包下面的类的时候,都要实现一个Serializable接口.
例如
public class implements Serializable
{
// 这里是一个L类型的数字
...
}
这有什么用啊?
这个接口没有提供任何方法,我们实现它有什么意义呢?还有就是,在一些抽象类/接口中,常使用Serializable做参数类型,比如public interface EntityDao<T>
{
T getEntityById(Serializable id);
}
似乎Serializable能代替String, int, Long...等成为一个更具普遍性的参数类型??
例如
public class implements Serializable
{
// 这里是一个L类型的数字
...
}
这有什么用啊?
这个接口没有提供任何方法,我们实现它有什么意义呢?还有就是,在一些抽象类/接口中,常使用Serializable做参数类型,比如public interface EntityDao<T>
{
T getEntityById(Serializable id);
}
似乎Serializable能代替String, int, Long...等成为一个更具普遍性的参数类型??
它有一个id 那个是全球唯一标识
用于区分 bean 对象
兄弟 希望对你有帮助哦
^_*
实现了序列化接口的
就能使用ObjectOutputStream和ObjectInputStream操作对象了
File file=new File("object.txt");
FileOutputStream out=new FileOutputStream(file);
ObjectOutputStream oos=new ObjectOutputStream(out);
QQ q=new QQ("lusi","male");
QQ q2=new QQ("sss","ss");
oos.writeObject(q);
oos.writeObject(q2);
oos.close();
}
如果QQ没有被标示为可序列化,就会报异常java.io.NotSerializableException:
被序列化的对象可以从一个jvm传输到另一个jvm上,然后目标jvm进行反序列化并使用。
也不知道对不