When we import List
from both java.awt.List
and java.util.List
, which one is selected when we refer to List
in subsequent code?
Asked
Active
Viewed 304 times
-4
-
1best way to find is implement and test. :) – Not a bug Jul 10 '14 at 10:16
-
2`java.util.List` as `java.lang.List` doesn't exist. – Peter Lawrey Jul 10 '14 at 10:16
-
1There is no `java.lang.List`. – Robby Cornelissen Jul 10 '14 at 10:16
-
4if you import both, the compiler will complain about an ambiguous type. you'll need to specify it yourself, like: java.lang.List a = new java.lang.List(); but I assume you just meant this as an example, since the java.lang.List interface doesn't exist. – Stultuske Jul 10 '14 at 10:16
-
1This has potential to be a good question if it's reworded, please don't close it just yet. – jr. Jul 10 '14 at 10:18
-
`java.awt.List` and `java.util.List` – akash Jul 10 '14 at 10:21
-
possible duplicate of [Importing two classes with same name. How to handle?](http://stackoverflow.com/questions/2079823/importing-two-classes-with-same-name-how-to-handle) – jr. Jul 10 '14 at 10:39
-
Also see: [How to import two classes with the same name in different packages?](http://stackoverflow.com/questions/3731125/how-to-import-two-classes-with-the-same-name-in-different-packages) – jr. Jul 10 '14 at 10:44
-
Asking of a construct not exists. You simply *cannot* import both. – johnchen902 Jul 10 '14 at 12:17
1 Answers
1
This cannot be done. A compile-time error similar to the following will occur:
The import java.awt.List collides with another import statement
The way to achieve this is to qualify one of the references.
import java.util.List;
public class Example
{
public static void main( String[] args )
{
List<String> stringList = new LinkedList<>();
java.awt.List guiList = new java.awt.List();
}

jr.
- 1,699
- 14
- 31