Steph
Steph

Reputation: 2049

Import not used over inherited nested class

My problem is quite simple: I want to use a class named Type (really org.eclipse.uml2.uml.Type in a Swing JDialog.

My code is (excerpt) :

import org.eclipse.uml2.uml.Type;

public class MyDialog extends JDialog {

    private List<Type> myTypes;

Problem is this does not work as expected. Eclipse tells me that the Type class mentioned in the myTypes declaration is really Window.Type, and my further code that uses this variable does not compile. I see that JDialog extends Dialog extends Window which contains a nested Type enum.

What surprises me is that, for instance when I want to use the Class class from uml package, I just import this Class class and the compiler is able to understand I want to use the Class in this import and not the Class class it would pick without the import (java.lang one). So it bugs me this does not work here, and I am obliged to use qualified name in all my code.

What further surprises me is that, according to the doc, this Window.Type enum was added in java 7, which means any code similar to mine would have worked until java 6 and suddenly stopped working in java 7, so a breaking change...

I use Java 8 and Eclipse Oxygen.

Is there something I miss? A compiler option or something? Is this expected and I have to live with it?

Upvotes: 0

Views: 53

Answers (1)

greg-449
greg-449

Reputation: 111142

That is how the Java Language Specification defines the scoping rules for member classes JLS §8.5 The Type member enum from Window is in scope so the import won't be used.

This isn't something that Eclipse is allowed to change as it must obey the specification.

You can refer to the UML class using its qualified name

private List<org.eclipse.uml2.uml.Type> myTypes;

Upvotes: 1

Related Questions