0

How is the dot allowed in this interface name, I cannot create another class/interface name with a dot in the name.

Puneet
  • 67
  • 3

3 Answers3

5

It's because Entry is a nested interface within the Map interface. You can create something similar if you want:

class MyClass {
  static class Nested { }
  public static void main(String[] args) {
    MyClass.Nested n = new MyClass.Nested();
  }
}

Or to answer your question more directly:

class MyClass {
  static class MyEntry implements Map.Entry { }
  public static void main(String[] args) {
    Map.Entry n = new MyEntry();
  }
  interface Map {
    interface Entry {}
  }
}
assylias
  • 321,522
  • 82
  • 660
  • 783
1

As Kevin Esche commented, when creating an inner class, it's fully qualified name would become foo.bar.Outer.Inner.

Kayaman
  • 72,141
  • 5
  • 83
  • 121
1

The Entry interface is declared in the Map interface. It's an inner interface. So in order to use it, we have to make a reference to Map class, hence the Map.Entry.

Zava
  • 400
  • 3
  • 16
  • 1
    Of course it's a public interface, otherwise you couldn't refer to it from another class. All members of an interface are automatically `public`, and `Map` is an interface, and `Entry` is a member of the interface `Map` so it's `public` too. – Erwin Bolwidt Jul 07 '16 at 13:22