Re: Forcing sub-classes to implement Constructor

Randall R Schulz <[email protected]>
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
On Thursday 09 August 2007 15:21, Victor Grazi wrote:
> No but if you have only a non default constructor then subclasses are
> forced to implement it.

If by "it" you mean a default (zer-argument) constructor, no that's not
true. It means only that the subclass must implement some constructor.


You know... If the superclass knows the names of the subclass(es), then
it could explicitly invoke zero-argument constructors for those
subclasses, which naturally forces them to exist. And if the
superclass's zero-argument constructor is private, then the
zero-argument constructor that would be produced by the compiler when
no explicit constructor is defined cannot be generated because it must
invoke the zero-argument superclass constructor, which it cannot do if
that constructor is private. And even if the superclass's constructor
is irrelevant to the subclasses (i.e., it would normally use the
default constructor), a protected dummy with a distinct argument
signature could be defined.

It's ugly, but it would work. Sort of.


Randall Schulz

> -----Original Message-----
>
> From:  Roger Jakobsen <[email protected]>
> Subj:  [ADVANCED-JAVA] Forcing sub-classes to implement Constructor
> Date:  Thu Aug 9, 2007 10:29 am
> Size:  284 bytes
> To:  [email protected]
>
> Is there a way to force subclasses of a class to implement a certain
> (read empty) constructor.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.