[3471] in java-interest
Re: declaration v.s. definition ambiguity
daemon@ATHENA.MIT.EDU (Gary Aitken)
Tue Nov 14 01:29:53 1995
Date: Mon, 13 Nov 1995 21:47:23 -0700
From: garya@village.org (Gary Aitken)
To: daconta@PrimeNet.Com (Michael Daconta), garya@village.org (Gary Aitken),
java-interest@java.sun.com
In-Reply-To: <199511132350.QAA23570@usr1.primenet.com>
>I would also agree that it can be called a class definition; however,
>since no storage space is reserved for this it goes against the
>ANSI C definition.
It may go against the ANSI C definition in some ways; I'm no language lawyer.
However, it does reserve storage for the class in the sense that it
reserves all the storage which is the implementation of the
methods for the class, plus all static members of the class.
Said another way, it reserves storage for all aspects of a class which
do not require additional storage allocation when an object of the class
is instantiated.
>I think it currently is:
>
>declaration: Only an announcement to the compiler of an identifier to be
>reserved in the current name space. In ANSI C, accomplished with the
>extern keyword. For functions accomplished by omitting the function body.
>For structures and classes accomplished with type identifier and no body.
>definition: An announcement to the compiler of an identifier to be
>reserved in the current name space. For primitive types, accompanied
>with a reservation of storage space. For user-defined types,
>accomplished by specifying the structure or class body. For functions
>accomplished by specifying the function body.
If I read the above correctly, the following is a declaration of Foo,
not a definition:
public static void main ( String argv[] ) {
MyClass foo;
}
But it seems to me this is a definition.
Also, abstract methods cannot have a body (unfortunately; should be may not)
As I understand the current syntax and semantics,
it seems to me that a declaration is:
An announcement to the compiler of an identifier to be reserved
in the current name space, with no storage allocation.
and a definition is:
An announcement to the compiler of an identifier to be reserved
in the current name space, together with the reservation of
storage for the identifier.
If we remember to take into account the difference between a class, and
an instance of a class, the above is all consistent. In a class definition,
the storage is allocated for the class itself -- the stuff which implements
the class; not an instance of the class.
A class, in java, is never just declared. It is declared
and defined in one operation. The definition amounts to allocating
storage for all aspects of the class which do not require additional
storage allocation when an object of the class is instantiated.
A class instantiation, such as the "MyClass foo;" above, is a
definition, as it reserves the storage associated with the instance.
An interface, in java, is always declared, but never defined,
since the definition of an interface is dependent on the class
which implements the interface; a definition for an interface
effectively occurs in the context of a class which implements
the interface.
Does this make sense?
And please remember I'm no expert on this -- Arthur or somebody else
should pass judgement on any statements like the ones I made above.
Gary Aitken garya@village.org
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com