0

I am using a function Map.entrySet(). When I am using import java.util.* it gives cannot find symbol error. But, when I am doing import java.util.Map.Entry it compiles. Shouldn't "*" include Map.Entry?

Am I missing anything?

Bottom line using import java.util.* gives me cannot find symbol error. For the same code import java.Map.Entry; does not. Why?

Thank You.

Valentin Michalak
  • 2,089
  • 1
  • 14
  • 27
Stif Spear Subba
  • 55
  • 1
  • 1
  • 10
  • 2
    Please show the actual code that fails to compile. – Sergey Kalinichenko Oct 15 '17 at 08:43
  • 1
    "Shouldn't "*" include Map.Entry?" I don't think so (if you use `Entry` directly you must `import j.u.Map.Entry`. Usually, `Map.Entry` is used not `Entry`) –  Oct 15 '17 at 08:47
  • As a side note, you should start using some IDE, they handle import for you ;) –  Oct 15 '17 at 08:49

1 Answers1

9

The star import is used for importing all classes of the package. When you specify

import java.util.*;

You are denoting that all classes that have full name java.util.<ClassName> are to be considered imported.

java.util.Map.Entry is an inner class of java.util.Map class. The star import for sub-classes will be something like this

import java.util.Map.*;

I can't say that it is a good practice to use start imports at all. Most of coding guidelines recommend to avoid it. Sub-class star imports isn't something you usually will come across in the code.

Aleh Maksimovich
  • 2,622
  • 8
  • 19