-
Enhancement
-
Resolution: Duplicate
-
P5
-
None
-
1.1.5
-
generic, x86
-
generic, windows_95
Name: tb29552 Date: 04/01/98
If I misspell the name of a method I'm overriding
in an anonymous class, I would expect the compiler
to generate an error, the way it does for a
misspelled variable name. For example, it took me
hours to spot the reason this didn't work:
theFrame.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent evt)
{
System.exit(0);
}
});
Editor's note: The correct name is:
"windowClosing(WindowEvent)." (Method in class java.awt.event.WindowAdapter)
There is no way to call the WindowClosing method,
so it shouldn't be allowed. Attempting to call it
will generate a compiler error, so I shouldn't be
allowed to do it at all.
Granted, it is legal to write this:
theFrame.addWindowListener(new WindowAdapter()
{
void someNewMethod()
{
System.exit(0);
}
public void windowClosing(WindowEvent evt)
{
someNewMethod();
}
});
So can understand why the compiler allows new
methods. But it's usually an error, so the
compiler should be smart enough to detect that
I've written a method that can't possibly be
called, and generate an error.
(Review ID: 27563)
======================================================================
- duplicates
-
JDK-4128179 # Add a lint-like facility to javac
-
- Closed
-