我有一个虚拟的Java程序,我想用Clojure编写它。它有一个实现Serializable接口的类和一个保存它的函数。由于我从未在Clojure中编写过这样的程序,我想知道正确的方法是什么,你会使用哪些Clojure数据结构和API调用来解决这个问题?
import java. io. *;
public class Box implements Serializable
{
private int width; private int height;
public void setWidth(int w)
{ width =w;}
public void setHeight(int h)
{height = h;}
}
public static void main (String[] args)
{
Box myBox =new Box();
myBox.setWidth(50);
myBox.setHeight(20) ;
try {
FileoutputStream fs = new File("foo.ser");
ObjectOUtputStream os = new ObjectOutputStream(fs);
os.writeObject(myBox);
os . close () ;
} catch (Exception ex) {} }