Re: Forcing sub-classes to implement Constructor

Jeff Kesselman <[email protected]>
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Alright, the forcing function is more complex and probably not useful to
you...  this is what it looks like to me

(1) All classes must have a constructor.  If none is dfined, a default
one is inferred.
(2) A super class's constructor must call a sub class's constructor.  If
it is not explciit, then again the defaiult constructor is inferred

SO the forcing mechanism is that IF the super class does not have a
default constructor THEN the consructor of a sub class must expolicitly
invoke the constructor the super-class *does* have.

If the super class has no default constructor but another one.  And the
sub class has no constructor (which ends  up meaning a default
consrtuctor that attempt
to call the super's default constructor)  THEN its an error.




Brian Maso wrote:
> No.
>
> Constructors are more like static methods than regular methods: they
> can't be declared abstract and thus force subclasses to have them. You
> can add tools to your build to recognize certain annotations that
> trigger verifier rules. For example, you could define an annotation
> such as:
>
> @SubclassConstructorRequiredPattern(presense=REQUIRED,
> constructor=PUBLIC_DEFAULT)
>
> which would be applied to the base class. Some part of your build then
> would scan code either jsut before or just after compilation to see if
> it breaks all the rules defined by such annotations.
>
> Sounds like an awful lot of work, though. What's your use-case? Why do
> you ned subclasses to supply a public default constructor?
>
> Brian Maso
>
> At 07:13 AM 8/9/2007, you wrote:
>> Is there a way to force subclasses of a class to implement a certain
>> (read
>> empty) constructor.
>>
>> mvh roger j
>>
>> ===================================
>> This list is hosted by DevelopMentor®  http://www.develop.com
>>
>> View archives and manage your subscription(s) at
>> http://discuss.develop.com
>
> ===================================
> This list is hosted by DevelopMentor®  http://www.develop.com
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com

===================================
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.