commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: CharRange UNSET ?
Date Sat, 28 Sep 2002 03:09:58 GMT
Yeah, method variables are that way.

I don't think instance/class variables are

public class Bob {

    private String name = null;

..

is overkill.

For example, I commonly see standard bean code like:

public Person {

    private int age;

    public int getAge() {
        return this.age;
    }

..

}

Looking at the spec, I think it says this is okay. Chapter 2, 2.5.1
_Initial Values of Variables_:

"Every variable in a program must have a value before it is used:

  *	Each class variable, instance variable, and array component is
initialized with a default value when it is created:"

it then goes on to detail the default values. Basically what you'd expect,
0, false or null.

I'd URL, but it's on my local machine. It's in 'Concepts.doc.html' if that
helps.

Hen

On Fri, 27 Sep 2002, Steve Downey wrote:

> public class TestDefAssign {
>   public static char UNSET;
>   public static void main(String[] args) {
>   char c;
>   char d = 0;
>   //System.out.println(d == c);
>   //System.out.println(d != c);
>   //System.out.println(c);
>   System.out.println(d != UNSET);
>   System.out.println(d == UNSET);
>   //System.out.println(c != UNSET);
>   //System.out.println(c == UNSET);
>   }
> }
>
> Uncomment any of the commented out lines and you get something like
> TestDefAssign.java:12: variable c might not have been initialized
>
> The output of the program is
> false
> true
>
> Which indicates that UNSET actually has the value of 0, but I don't think
> you're supposed to use it.
>
>
> On Friday 27 September 2002 06:36 pm, Henri Yandell wrote:
> > Weird. I'd thought all values in Java were set to a defined value. Thought
> > we got rid of the unassigned stuff with C. But I don't delve into the JVM
> > and language spec enough so could be wrong very easily.
> >
> > Hen
> >
> > On 27 Sep 2002, Steve Downey wrote:
> > > CharRange uses an unassigned static character, UNSET, as a flag value
> > > for testing if the range is a range or a single value.
> > >
> > > This looks a little odd to me. I had the distinct impression that
> > > accessing an unassigned value was an error. However, the comparison
> > > works. I'm just not sure it's working as intended, and won't fail to
> > > work an a different VM?
> > >
> > > relevant code:
> > >     /**
> > >      * Used internally to represent null in a char.
> > >      */
> > >     private static char UNSET;
> > >
> > > // ...
> > >
> > >     /**
> > >      * Is this CharRange over many characters
> > >      *
> > >      * @return boolean true is many characters
> > >      */
> > >     public boolean isRange() {
> > >         return this.close != UNSET;
> > >     }
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <mailto:commons-dev-unsubscribe@jakarta.apache.org> For additional
> > > commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message