class OO implements Serializable { private int i = 0; private String s = "好"; public int getSize() { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(this); } catch (IOException e) { e.printStackTrace(); } return bos.size(); } }