网络中如果你要通过Socket传送数据,并且数据使用Object组织的,那么,这个对象就必须是Serializable才行。
实际编程中,Serializable接口没有具体的方法需要实现,假如你要将A 类的对象a通过Socket传送,则A类必须声明为Serializable的。
如下的类的对象就可通过Socket传送public class InvocationEvent implements java.io.Serializable{
String componentName;
String methodName;
Object[] args; public InvocationEvent() {
}
public InvocationEvent(String componentName, String methodName, Object[] args) {
this.componentName = componentName;
this.methodName = methodName;
this.args = args;
} public String getComponentName() {
return componentName;
}
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public Object[] getArguments() {
return args;
}
public void setArguments(Object[] args) {
this.args = args;
}
}
实际编程中,Serializable接口没有具体的方法需要实现,假如你要将A 类的对象a通过Socket传送,则A类必须声明为Serializable的。
如下的类的对象就可通过Socket传送public class InvocationEvent implements java.io.Serializable{
String componentName;
String methodName;
Object[] args; public InvocationEvent() {
}
public InvocationEvent(String componentName, String methodName, Object[] args) {
this.componentName = componentName;
this.methodName = methodName;
this.args = args;
} public String getComponentName() {
return componentName;
}
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public Object[] getArguments() {
return args;
}
public void setArguments(Object[] args) {
this.args = args;
}
}
具体应用如保存文件,网络,不过在做保存文件之类的应用之前请三思...因为版本之间的兼容问题非常头疼,如果有谁解决了这个问题,望告之.