---
title: "setcontent和setcontentobject用的是同一片内存"
author: "turingfellow"
date: "2010-04-10T17:05:03Z"
tags: []
categories: ["编程语言"]
slug: "setcontent-setcontentobject"
draft: false
lastmod: "2010-04-10T17:11:45Z"
id: 640833
url: "https://turingfellow.iteye.com/blog/640833"
---

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
>
>