Menu

#21 importing superfluous package cause compile error

open
nobody
None
2
2004-06-27
2004-03-01
No

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.

Discussion

  • Daniel Bonniot

    Daniel Bonniot - 2004-03-01

    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?

     
  • Jason Thomas

    Jason Thomas - 2004-03-02

    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.

     
  • Daniel Bonniot

    Daniel Bonniot - 2004-03-02

    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?

     
  • Arjan Boeijink

    Arjan Boeijink - 2004-06-27
    • priority: 5 --> 2
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.