【发布时间】:2011-08-25 20:50:10
【问题描述】:
这段代码...
class A implements Serializable{
String str
int n
}
try{
def a= new A(str:'abc', n:7)
def out= new ObjectOutputStream(new FileOutputStream('serializedObject.obj'))
out.writeObject(a)
out.close()
}finally{}
try{
def inp= new ObjectInputStream(new FileInputStream('serializedObject.obj'))
def a2= inp.readObject()
inp.close()
}finally{}
...产生错误...
java.lang.ClassNotFoundException: A
at java_io_ObjectInput$readObject.call(Unknown Source)
at otherRun.run(otherRun.groovy:16)
...尝试在第二个尝试块中重新加载对象时。当类是预定义类(如 java.util.List)时,它可以正常工作。 将逐行转换为 Java 时,上述代码也可以正常工作。
如何让它在 Groovy 中工作?
【问题讨论】:
标签: groovy