> So, should a java compiler accept the following?
>
> // java.awt.HeadlessException
> //   extends java.lang.UnsupportedOperationException
> //     extends java.lang.RuntimeException
>
> class Foo
> {
>   void meth() throws java.awt.HeadlessException { }
> }
>
> class Bar
>   extends Foo
> {
>   void meth() { }
> }

The code is valid in that its okay for a subclass to declare fewer
exceptions on an overriding method - checked or unchecked. Hence
Bar.meth is correctly defined and must be accepted by any compiler.

However, a compiler could complain that Foo.meth can never throw the
declared HeadlessException (as it should for a checked exception) and
refuse to compile it. I think it would be a bit over-zealous, though
not "illegal", to do so.

David Holmes



_______________________________________________
Classpath mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/classpath

Reply via email to