Troubleshooting

   

Class Should Be Declared Abstract

The compiler reports that a class should be declared abstract because it does not implement a particular method.

A class that is declared to implement an interface must explicitly be declared as abstract if it does not implement every method defined by that interface and its super-interfaces. If you don't intend for the class to be abstract , examine the signature for the method named in the compiler error to determine why your implementation does not match. To correctly override an interface method, you must define a method with the exact same name and parameter list.

Invalid Method Implementation Because of a Thrown Exception

The compiler reports that a method in your class cannot implement an interface method because that interface method does not throw a particular exception.

When you override an interface method, the exception list in its throws clause can only contain exceptions found in the interface's declaration of the method, or subclasses of those exceptions. For example, you cannot declare a method to throw java.lang.Exception if the interface method it is intended to override is declared to only throw java.io.IOException . You would instead have to handle any exceptions other than java.io.IOException and its subclasses. Resolve this error by comparing the exception list of the interface method declaration to that found in your implementation.

Invalid Method Implementation Because of Return Type

The compiler reports that a method in your class cannot implement an interface method because the return type is different.

As with any method override, the implementation of an interface method must not change the return type. Resolve this error by comparing the return type of the interface method declaration to that stated in your implementation.

ClassCastException When Casting to an Interface

A ClassCastException occurs when an attempt is made to cast an object to a particular interface even though you have overridden each of the interface methods in the object's class.

A class can only implement an interface if its declaration includes an implements clause that names the interface. Add the necessary implements clause to your class and recompile it to correct this problem.

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net