setcontent和setcontentobject用的是同一片内存

探讨了在使用ACL消息系统中setContent和setContentObject方法时出现的问题。当同时使用这两种方法时,后者会覆盖前者的内容,导致输出乱码。解释了乱码产生的原因,并提供了源代码检查确认该行为符合预期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

setcontent 和 setcontentobject用的是同一片内存,也就是在同一个信息里只宜用一个方法,如果用了两个,第二个会重写第一个的内容,收到的会是一个乱码.
Ok I understand now. I didn t remarked that setContent and
setContentObject referred to the same slot.
Thanks a lot,

Emmanuel

Emilio Yamane a écrit :

> My comments after the ">>>":
>
> On 4/21/06, *blanchae at iro.umontreal.ca
> <mailto:blanchae at iro.umontreal.ca>* <blanchae at iro.umontreal.ca
> <mailto:blanchae at iro.umontreal.ca>> wrote:
>
> A test I just did:
>
> sendMessageAndObject(ACLMessage.AGREE,"MAP_DATA",new
> String("ABCDEFGH"), msg.getSender());
>
> and here is the message that is shown on my console (Corresponding
> to the
> following call inside my sendMessageAndObject method :
> System.out.println(msg.getContent()+" "+msg.getContentObject()); )
>
> ¼? ?ABCDEFGH ABCDEFGH
>
> Sounds very very strange to me...
> why "MAP_DATA" is not return by getContent?
>
>
> >>> Because in your method, you call setContent AND setContentObject.
> According to the model, they both would write to the same slot in ACL
> Message (:content).
>
> >>> After you set the content with "MAP_DATA", you call
> setContentObject and it "rewrites" the content with your String .
>
>
> Where do the symbols come from?
>
>
> >>> Since you called setContentObject after setContent, your message
> carries a serialized java object (in a byte array). When you call
> getContent, it will try to build a String based on the byte array. As
> the byte array contains also information about the String class (and
> not just the String itself), the strange chars are explained.
>
> Could it be a jade bug?
>
>
> >>> I took a look at the source code, and it seems OK.
>
> Emmanuel
>
>
> >>> []s Emilio
>
>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值