Article View: borland.public.jbuilder.java.language
Article #17301Re: class = null ?!
From: Steve Schafer (TeamB)
Date: Fri, 27 Nov 1998 00:00
Date: Fri, 27 Nov 1998 00:00
34 lines
1892 bytes
1892 bytes
On Sat, 28 Nov 1998 00:20:41 +0300, Vladimir Olenin
<keenonjava@collegemail.com> wrote:
>Other days i figure the problem out. I've attached minimal code to this
>letter. The problem was that when Data class (in the attached files it's
>pack.class) had only static fields, then it was possible to intitialize
>the fields only, without intitializing class. That's why pointer to that
>class was null.
To clarify the terminology: Static fields are associated with a class,
while other "normal" fields are associated with an _instance_ of a
class. In order to create an instance of that class, you have to use
the "new" operator. You use the expression "pointer to that class,"
but that's not correct. Your pointer was not a pointer to the class,
it was a pointer to an _instance_ of that class. Since you had never
used the "new" operator, no instance was ever created, and that's why
the pointer was null. Because the static variables were associated
with the class itself (which already existed), you could access them
without any problem.
By the way, it is possible to initialize a class itself; you can do
this with a static initialization section:
public class Foo {
...
static {
// class initialization goes here
}
}
-Steve
Technical Details
Message-ID:
<36a52049.310401141@90.0.0.40>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<36586170.A4A677D4@collegemail.com> <36798e4f.230406438@90.0.0.40> <365F17A9.129E7CE3@collegemail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,6cc14c4eb4d410f7 X-Google-Attributes: gidf74b3,public From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: class = null ?! Date: 1998/11/27 Message-ID: <36a52049.310401141@90.0.0.40> X-Deja-AN: 416322243 Content-Transfer-Encoding: 7bit References: <36586170.A4A677D4@collegemail.com> <36798e4f.230406438@90.0.0.40> <365F17A9.129E7CE3@collegemail.com> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.jbuilder.java.language