unclejohn00
unclejohn00

Reputation: 149

Eclipse library

there are two types of data that can be easly mixed up by the compiler. Here they're:

java.util.List

and

org.eclipse.swt.widgets.List

I need both in a method I have created and the only workaround I have found is to use the absolute path in the declaration section, at least for one of those types. I.e: java.util.List<String> listofstring;

Any hints?

Upvotes: 1

Views: 43

Answers (1)

bdulac
bdulac

Reputation: 1666

According to the Java Language Specification, there is no workaround (except for a type parameter what would not be a very good idea).

§7.5 is the section about import declaration: an imported type is being refereed to by its simple name :

A single-type-import declaration (§7.5.1) imports a single named type, by mentioning its canonical name

The scope of the import is the importing type - §6.3:

The scope of a declaration is the region of the program within which the entity declared by the declaration can be referred to using a simple name, provided it is visible

You should not have two same simple names because of shadowing - §6.4:

Some declarations are not permitted within the scope of a local variable, formal parameter, exception parameter, or local class declaration because it would be impossible to distinguish between the declared entities using only simple names.

Upvotes: 1

Related Questions