Re: acces of members of subclass
On Jul 28, 5:16 pm, Eric Sosman <Eric.Sos...@sun.com> wrote:
You said "The call to super() is *always* present," but that i=
s
not the case. It is absent in three cases: (1) the class happens to
be java.lang.Object, (2) there is an explicit call to a superclass
constructor other than super(), or (3) the superclass has no no-
arguments constructor. Case (1) need not concern us, but case (2)
is perfectly ordinary, and case (3) is code that cannot produce a
"given class" because it won't even compile.
Case 1 did not concern me, agreed. For case2, a superclass
constructor call is always 'super()', it just may be 'super()' with
arguments. It is conventional in Usenet discussions to refer to a
constructor or method generally without regard for the arity. That is
what I did. So case 2 is covered by what I said, since there is no
call to a superclass constructor save through 'super()', in some
arity, implicit or explicit. Case 3 does not produce a class, so
therefore if there is a "given class", it has a 'super()' call. QED.
Lew (and the JLS) are right in saying that the compiler ins=
erts a
call to super() if the constructor does not begin with a call to one
How can I be wrong if I said the same thing that the JLS does?
I said you "are right," did I not?
Actually, what you said was, "No, Mark is right, and Daniel and Lew
are wrong. "
I suspect we may be in violent agreement, differing only in ou=
r
use of nomenclature. When you refer to a "given class," it seems you
mean a bunch of source code processed by javac, whether or not it can
be compiled. I take the word "class" to mean the thing loaded into
the JVM by a ClassLoader, so in my view an uncompilable source cannot
become a "class."
Therefore by your definition, a given class always has a 'super()'
call in its constructors, else there would be no class to be "given".
Violent agreement indeed.
I don't know why you imputed a source-code only context to my claim
when it works in the scenario you had in mind, that of compiled
classes. If there is a compiled class, there is a 'super()' call in
each of its constructors. We agree. Violently.
In addition, it is also true that that call exists in code that fails
to compile correctly due to an inaccessible superclass constructor. I
only ever claimed that the call exists. In fact, the belief that it
does *not* exist leads to the bug that a unit will not compile because
the author didn't account for accessibility of the superclass
constructor. It is the belief that the superclass constructor does
*not* always exist that leads to bugs. Understanding that the
superclass constructor call is *always* present leads to more correct
code.
You are right: The compiler will decorate constructors with ca=
lls
to super() in the absence of explicit calls to superclass constructors.
This is the sum total of what I asserted.
I am right: Classes without calls to super() exist, and superc=
lasses
exist that cannot be constructed via super() calls.
You were right in your analysis, only mistaken in thinking that I had
disagreed with it.
--
Lew