麻烦克隆扩展的ByteArray [英] Trouble cloning an extended ByteArray

查看:165
本文介绍了麻烦克隆扩展的ByteArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经扩展了ByteArray类,像这样的:

I've extended the ByteArray class, like this:

[RemoteClass(alias="MyByteArray")]
public class MyByteArray extends ByteArray {}

和克隆使用的ByteArray#的readObject(这个类的一个实例)/的writeObject()。然而,由于某些原因,克隆对象的ByteArray而非MyByteArray的一个实例。这表示在下面的示例:

and cloned an instance of this class using ByteArray#readObject()/writeObject(). However, for some reason, the cloned object is an instance of ByteArray rather than MyByteArray. This is illustrated in the following example:

registerClassAlias("MyByteArray", MyByteArray);
var b1:MyByteArray = new MyByteArray();
var tmp:ByteArray = new ByteArray();
tmp.writeObject(b1);           
tmp.position = 0;
var b2:* = tmp.readObject();
trace( b2 is MyByteArray ); // prints false
trace( b2 is ByteArray ); // prints true

此外,当我在MyByteArray类添加一些自定义字段,他们没有保存的writeObject(),并没有克隆...

Moreover, when I add some custom fields in MyByteArray class, they aren't saved with writeObject() and neither cloned...

任何人都可以解释我为什么克隆的对象不是MyByteArray的一个实例?

Can anybody explain me why the cloned object is not an instance of MyByteArray?

非常感谢!

推荐答案

我想这是因为TMP是不是类型MyByteArray ByteArray类型。如果你把类型MyByteArray的TMP,它应该返回相同类型的对象,使用的writeObject我觉得呢?或者,你可能需要强制转换了。

I think this is because tmp is of type ByteArray, not of type MyByteArray. If you make tmp of type MyByteArray, it should return an object of the same type, using writeObject i think? Or you may need to typecast it.

这篇关于麻烦克隆扩展的ByteArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆