interface可以为空??

phonlee 2003-02-27 10:42:25
下面是jdk源代码, 其中接口中什么也没有定义??

请问什么情况下这么干??




/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/

package java.io;

/**
* Serializability of a class is enabled by the class implementing the
* java.io.Serializable interface. Classes that do not implement this
* interface will not have any of their state serialized or
* deserialized. All subtypes of a serializable class are themselves
* serializable. The serialization interface has no methods or fields
* and serves only to identify the semantics of being serializable. <p>
*
* To allow subtypes of non-serializable classes to be serialized, the
* subtype may assume responsibility for saving and restoring the
* state of the supertype's public, protected, and (if accessible)
* package fields. The subtype may assume this responsibility only if
* the class it extends has an accessible no-arg constructor to
* initialize the class's state. It is an error to declare a class
* Serializable in this case. The error will be detected at runtime. <p>
*
* During deserialization, the fields of non-serializable classes will
* be initialized using the public or protected no-arg constructor of
* the class. A no-arg constructor must be accessible to the subclass
* that is serializable. The fields of serializable subclasses will
* be restored from the stream. <p>
*
* When traversing a graph, an object may be encountered that does not
* support the Serializable interface. In this case the
* NotSerializableException will be thrown and will identify the class
* of the non-serializable object. <p>
*
* Classes that require special handling during the serialization and deserialization
* process must implement special methods with these exact signatures: <p>
*
* <PRE>
* private void writeObject(java.io.ObjectOutputStream out)
* throws IOException
* private void readObject(java.io.ObjectInputStream in)
* throws IOException, ClassNotFoundException;
* </PRE><p>
*
* The writeObject method is responsible for writing the state of the
* object for its particular class so that the corresponding
* readObject method can restore it. The default mechanism for saving
* the Object's fields can be invoked by calling
* out.defaultWriteObject. The method does not need to concern
* itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput. <p>
*
* The readObject method is responsible for reading from the stream and restoring
* the classes fields. It may call in.defaultReadObject to invoke
* the default mechanism for restoring the object's non-static and non-transient
* fields. The defaultReadObject method uses information in the stream to
* assign the fields of the object saved in the stream with the correspondingly
* named fields in the current object. This handles the case when the class
* has evolved to add new fields. The method does not need to concern
* itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput. <p>
*
* Serializable classes that need to designate an alternative object to be
* used when writing an object to the stream should implement this
* special method with the exact signature: <p>
*
* <PRE>
* ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
* </PRE><p>
*
* This writeReplace method is invoked by serialization if the method
* exists and it would be accessible from a method defined within the
* class of the object being serialized. Thus, the method can have private,
* protected and package-private access. Subclass access to this method
* follows java accessibility rules. <p>
*
* Classes that need to designate a replacement when an instance of it
* is read from the stream should implement this special method with the
* exact signatute.<p>
*
* <PRE>
* ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
* </PRE><p>
*
* This readResolve method follows the same invocation rules and
* accessibility rules as writeReplace.
*
* @author unascribed
* @version 1.17, 02/06/02
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @see java.io.ObjectOutput
* @see java.io.ObjectInput
* @see java.io.Externalizable
* @since JDK1.1
*/
public interface Serializable {
}
...全文
110 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
teddy_huang 2003-02-27
  • 打赏
  • 举报
回复
//shy,说错了,孰能无过?
java.rmi.Remote这个是,标志实现了Remote接口的类可被远程调用
xxycumt 2003-02-27
  • 打赏
  • 举报
回复
可以为空的
hayai 2003-02-27
  • 打赏
  • 举报
回复
谁说runnable是空的了?不是有个run函数吗?不要掏浆糊!!!!
abcnn 2003-02-27
  • 打赏
  • 举报
回复
这个接口本身只是意味着实现它的类可以被串行化,空意味着实现它的类不需要实现任何方法就可以实现串行化了。
bluesmile979 2003-02-27
  • 打赏
  • 举报
回复
标志性接口,实现了他的子类用来向系统声明自己确保某某功能已经在这里实现,可以安全使用

比如你这里提到的,implement了Serializable 的类向系统保证自己实现序列化功能(自己是可序列化的)系统才对你有相关处理,否则就算你的类是“可“序列化的,没有implements这个接口,系统不能对他做序列化处理。
teddy_huang 2003-02-27
  • 打赏
  • 举报
回复
java.io.Serializable和java.lang.Runnable都是这样的
lotofu 2003-02-27
  • 打赏
  • 举报
回复
可以为空。
colors 2003-02-27
  • 打赏
  • 举报
回复
学习到了好东西了
Patrick_DK 2003-02-27
  • 打赏
  • 举报
回复
序列化接口

这是一个典型的Java标志型接口(Flag Interface)

一般不推荐开发人员自己设计这样的接口

这样的接口主要是向JVM提供信息,以确定实现这标志型接口的类可以得到JVM的某些特殊处理
Go语言性能好、语法简单、开发效率高!一起来探索Go 语言吧!本课程特别适合从事PHP/Python/Ruby/Node.js等Web开发的读者,通过本课程可以了解编译型语言怎么写Web应用开发,系统底层怎么进行网络通信。 beego 简介beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,主要设计灵感来源于 tornado、sinatra 和 flask 这三个框架,但是结合了 Go 本身的一些特性(interface、struct 嵌入等)而设计的一个框架。beego 的架构beego 的整体设计架构如下所示:beego 是基于八大独立的模块构建的,是一个高度解耦的框架。当初设计 beego 的时候就是考虑功能模块化,用户即使不使用 beego 的 HTTP 逻辑,也依旧可以使用这些独立模块,例如:你可以使用 cache 模块来做你的缓存逻辑;使用日志模块来记录你的操作信息;使用 config 模块来解析你各种格式的文件。所以 beego 不仅可以用于 HTTP 类的应用开发,在你的 socket 游戏开发中也是很有用的模块,这也是 beego 为什么受欢迎的一个原因。大家如果玩过乐高的话,应该知道很多高级的东西都是一块一块的积木搭建出来的,而设计 beego 的时候,这些模块就是积木,高级机器人就是 beego。至于这些模块的功能以及如何使用会在后面的文档逐一介绍。beego 的执行逻辑既然 beego 是基于这些模块构建的,那么它的执行逻辑是怎么样的呢?beego 是一个典型的 MVC 架构,它的执行逻辑如下图所示:beego 项目结构一般的 beego 项目的目录如下所示:├── conf│   └── app.conf├── controllers│   ├── admin│   └── default.go├── main.go├── models│   └── models.go├── static│   ├── css│   ├── ico│   ├── img│   └── js└── views    ├── admin    └── index.tpl从上面的目录结构我们可以看出来 M(models 目录)、V(views 目录)和 C(controllers 目录)的结构, main.go 是入口文件。
Re:CCNA_CCNP 思科网络认证 动态路由 RIP 协议======================# RIP 协议中 network的作用 rip协议种network的应该怎么写 作用network 用来配置路由器:哪些接口参与到RIP协议中,功能如下: 接口能够发送和接收RIP数据包 该接口所在的网段会被RIP协议通告出去 方法:分析接口属于哪个网络(子网掩码默认,故需先分清A、B、C类地址) 多个接口属于同一个网段(按A、B、C分类),只需写一个。 # RIP协议工作过程 静态路由存在的问题 RIP协议工作特点 配置RIP协议 查看RIP协议学习到的路由 network的应该怎么写 查看运行的RIP协议 查看RIP协议活动 RIPv1和RIPv2的区别 变长子网和等长子网 连续子网和不连续子网 RIPv2关闭自动汇总支持不连续子网 # 小型网络动态路由协议:RIP协议 路由信息协议RIP(Routing Information Protocol) 是一个真正的距离矢量路由选择协议。 它每隔30秒就送出自己完整的路由表到所有激活的接口。 建议终结端口可以关闭(#passive-interface fastEthernet 0/0) RIP协议选择最佳路径的标准就是跳数, 认为到达目标网络经过的路由器最少(跳数)的路径就是最佳路径。 暂时不以带宽为标准(后续...) 默认它所允许的最大跳数为15跳,也就是说16跳的距离将被认为是不可达的。 过期的路由信息被设置成16跳而非删除,原因为下次能够快速恢复 在小型网络中,RIP会运转良好, 但是对于使用慢速WAN连接的大型网络或者安装有大量路由器的网络来说, 它的效率就很低了。建议EIGRP和OSPF协议更适合 # rip 协议工作原理(图解) # 验证RIP协议健壮性 观察RIP协议更新路由信息的活动 # RIP协议默认会在网段类的边界自动汇总路由信息 不连续子网需要关闭RIP协议自动汇总功能 关闭RIP自动汇总的情况下:执行手工精确汇总 # RIP 协议定时器# RIP阻止路由环路的方案------------------------------------              

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧