importing superfluous package cause compile error
Brought to you by:
bonniot
This program compiles fine, but if you uncomment out
the superfluous import you get the error "Pattern null is
incompatible with type
org.eclipse.swt.widgets.Composite"
package test;
//import org.eclipse.jface.dialogs.*(!);
import org.eclipse.jface.wizard.*(!);
import org.eclipse.swt.widgets.*(!);
public class TestWizard extends WizardPage {
createControl(null) {
}
createControl(Composite parent) {
}
}
Note: swt.jar and jface.jar needed to compile.
Logged In: YES
user_id=88952
This seems normal behaviour to me. The method
'createControl' is declared in package
'org.eclipse.jface.dialogs'. If you don't specify '(!)' for
that package, it is interpreted as having a parameter of
type ?Composite, in which case you can (and must) handle the
case where the parameter is null. On the other hand, if you
remove the commented line, then you assert in particular
that the argument of this method cannot be null. In this
case, the compiler rightfully complains that "Pattern null
is incompatible with type org.eclipse.swt.widgets.Composite".
Is there a problem with this behaviour?
Logged In: YES
user_id=143037
You shouldn't need to be concious of what package an
overridden method is declared. You may not even know
where it's declared if it's a 3rd party library.
Logged In: YES
user_id=88952
I see what's surprising. On the other hand, it does not make
sense to say that a method does not accept null, if it
overrides a method that does.
Normally you know where a method is declared, because
javadoc has those 'overrides' links to the original method.
So knowing where a method is declared should not be an issue.
Is this a major issue for you? Can you suggest a different
behaviour?