harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ellison <t.p.elli...@gmail.com>
Subject Re: [classlib] compatibility of toString
Date Mon, 03 Jul 2006 10:07:48 GMT
Andrew Zhang wrote:
> On 7/1/06, Alex Blewitt <alex.blewitt@gmail.com> wrote:
>>
>> On 01/07/06, Andrew Zhang <zhanghuangzhu@gmail.com> wrote:
>> >
>> > Agree. But there are always exceptions. Some "toString" methods have to
>> > contain some key information as spec required, for example, the size or
>> > index.
>>
>> Can you give examples of where the spec specifically mandates the
>> return values of either size or index?
> 
> 
> What I mean is in some cases, toString returns a string is not enough.
> e.g. "Harmony is Great"  obviously doesn't comply with spec
> AbstractCollection.toString() as you mentioned below.
> Another example is CharBuffer.toString(). The spec says:
> "Returns a string containing the characters in this buffer.
> The first character of the resulting string will be the character at this
> buffer's position, while the last character will be the character at index
> limit() - 1. Invoking this method does not change the buffer's position. "
> 
> Therefore, for these special cases, tests for toString are useful. Of
> course, instead of comparing Harmony's toString return value with RI's, the
> test should verify whether Harmony's toString value complys with spec. The
> test should not look like:
> assertEquals(RI_TOSTRING, instance.toString());
> For CharBuffer.toString, the test may be written as following:
> assertEquals(the character at this bufer's position, the first character of
> toString);
> ....
> 
> For most other cases, IMO, Harmony doesn't need to keep the same return
> value as RI's.
> 
> Thanks!

Yep, if the spec tells you what the format of the string should be then
follow it (since apps may be dependent upon it), otherwise I'd be
inclined to invent your own useful string representation.

Regards.
Tim

>> BTW, are these toString information (RI) copyrighted?
>>
>> I don't believe they can be copyrighted. However, the only way to tell
>> if the RI and Harmony return the same results would be to execute both
>> and compare them, and I believe that such reverse engineering would be
>> outside the remit of Harmony.
> 
> 
> Agree.
> 
> I doubt that the TCK would test for such
>> features exactly, without specifying them. For example, the
>> AbstractCollection and AbstractMap does specify what it should return:
>>
>>
>> http://java.sun.com/j2se/1.5.0/docs/api/java/util/AbstractCollection.html#toString()
>>
>>
>> http://java.sun.com/j2se/1.5.0/docs/api/java/util/AbstractMap.html#toString()
>>
>>
>> I think you'd find it difficult to explain why (in all cases)
>> toString() returned exactly the same value as the RI without such
>> detailed comments as to their format :-)
>>
>> Alex.
>>
>> ---------------------------------------------------------------------
>> Terms of use : http://incubator.apache.org/harmony/mailing.html
>> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
>> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>>
>>
> 
> 

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org


Mime
View raw message