In a message dated Tue, 8 Oct 2002, Michael G Schwern writes:

> On Sun, Oct 06, 2002 at 06:17:37PM -0400, Daniel B. Boorstein wrote:
> > I think there may be some confusion here. In java, there's no special syntax
> > to declare a method an optional part of the interface. All concrete classes
> > that implement the Collection interface still must define full-bodied
> > C<add(Object element)> methods. It just so happens that by convention some
> > classes simply throw an UnsupportedOperationException, perhaps like so:
>
> AHHHH!  No wonder I couldn't find any syntax for it!  Thanks for clearing
> that up.
>
> Still, the objections still hold, though now it's a stylistic objection
> rather than syntactic.  It's disturbing that they'd put these optional
> methods into the core Java API, thereby encouraging their use ("Sun did it,
> so I can to!").  Cannonizing the idea weakens the whole concept of an
> interface and contract.
>
> It really ought to be one of those "sure you can do this, but please don't"
> things.

It's a RuntimeException.  You can't require that all RuntimeExceptions be
declared if thrown; otherwise, every method would have to declare "throws
OutOfMemoryException, CannotLoadClassException,
TheEndTimeIsUponUsException, ..."  for every single runtime error.  You
can subclass RuntimeException.  So if Sun hadn't provided an
UnsupportedOperationException, anyone else could easily have done so.

And they'll be able to in Perl, too, whatever you do.  I often code

method foo {
  die "Abstract method foo not implemented in concrete class" .
     (ref $_[0] || $_[0]) . ", died";
}

In my abstract superclasses, which is the very same thing.

Trey

Reply via email to