harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liou <lcj....@gmail.com>
Subject Re: Question about Character.valueOf()
Date Wed, 17 Nov 2010 08:44:24 GMT
Does that means impl of harmony widened the range on the jls from
0-127 to 0-512?

On Tue, Nov 16, 2010 at 11:23 PM, sebb <sebbaz@gmail.com> wrote:
>
> Yes, but the point is that there is at least a partial guarantee.
>
> On 16 November 2010 14:55, Mikael <mikael-aronsson@telia.com> wrote:
> > But that's only for Character 0x00 to 0x7F, the loop with the assert test
> > counts from 0 to 512.
> >
> > ----- Original Message ----- From: "sebb" <sebbaz@gmail.com>
> > To: <dev@harmony.apache.org>
> > Sent: Tuesday, November 16, 2010 3:42 PM
> > Subject: Re: Question about Character.valueOf()
> >
> >
> > The end of section 5.1.7
> >
> > http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.7
> >
> > says:
> >
> > "If the value p being boxed is true, false, a byte, a char in the
> > range \u0000 to \u007f, or an int or short number between -128 and
> > 127, then let r1 and r2 be the results of any two boxing conversions
> > of p. It is always the case that r1 == r2."
> >
> > [See also subsequent discussion section]
> >
> > AFAIK, boxing uses valueOf to achieve this.
> >
> > On 16 November 2010 13:50, Mikael <mikael-aronsson@telia.com> wrote:
> >>
> >> As far as I know there is no guarantee that valueOf returns the same
> >> object
> >> every time, it just gives class a chance to do it if it wants to.
> >>
> >> ----- Original Message ----- From: "lcj.dev" <lcj.dev@gmail.com>
> >> To: "dev" <dev@harmony.apache.org>
> >> Sent: Tuesday, November 16, 2010 2:44 PM
> >> Subject: Question about Character.valueOf()
> >>
> >>
> >>> Hi, all
> >>> Why this may be failed for other JREs? assertSame(Character.valueOf(c),
> >>> Character.valueOf(c)).
> >>> Thanks.
> >>>
> >>> please refers to this test case for details:
> >>> package org.apache.harmony.luni.tests.java.lang;
> >>>
> >>> import junit.framework.TestCase;
> >>>
> >>> public class CharacterImplTest extends TestCase {
> >>>
> >>> public void test_valueOfC() {
> >>> // test the cache range
> >>> for (char c = '\u0000'; c < 512; c++) {
> >>> Character e = new Character(c);
> >>> Character a = Character.valueOf(c);
> >>> assertEquals(e, a);
> >>>
> >>> // WARN: this assertion may not be valid on other JREs
> >>> assertSame(Character.valueOf(c), Character.valueOf(c));
> >>> }
> >>> // test the rest of the chars
> >>> for (int c = '\u0512'; c <= Character.MAX_VALUE; c++) {
> >>> assertEquals(new Character((char) c), Character.valueOf((char)
> >>> c));
> >>> }
> >>> }
> >>> }
> >>> 2010-11-16
> >>>
> >>>
> >>>
> >>> lcj.dev
> >>
> >>
> >
> >

Mime
View raw message