1

as the title says, why nested interfaces are implicitly static.Why cant i use nested interfaces just like nested classes ie like with static and without static

deshmanth
  • 529
  • 5
  • 12
  • Refer http://cs-fundamentals.com/java-programming/java-static-nested-or-inner-interfaces.php – Anptk Feb 04 '15 at 12:42
  • @Zeeker, not so. OP is asking about interface definitions themselves, not their members. – robert Feb 04 '15 at 14:06
  • @robert He is asking about nested interface, speaks interfaces in interfaces. In that case the nested interface is just a member of another interface. At least if I understand the question correctly. – Sascha Wolf Feb 04 '15 at 14:09
  • @Zeeker, that would be an *instance* of an interface (or strictly speaking an instance of an object that implements the interface). He's asking about interface declaration. – robert Feb 04 '15 at 14:12
  • @robert I think you misunderstood my comment. – Sascha Wolf Feb 04 '15 at 14:14
  • http://www.programcreek.com/2013/08/inner-interface-in-java/ – robert Feb 04 '15 at 14:33
  • Because [JLS §8.5.1](https://docs.oracle.com/javase/specs/jls/se9/html/jls-8.html#jls-8.5.1). Duplicate. – user207421 Feb 28 '18 at 01:32

2 Answers2

0

From the oracle documentation:

an inner class is associated with an instance of its enclosing class and has direct access to that object's methods and fields

i.e. it maintains a reference to its enclosing instance.

An interface on the other and is just a static definition of type. A contract, used to provide some polymorphism.

An interface cannot itself be instantiated, therefor it cannot have state, and thus it cannot "know" about an enclosing instance.

robert
  • 4,612
  • 2
  • 29
  • 39
-2

Java interface are interfaces. A interface rule is ACID. The I in ACID means:

To demonstrate isolation, we assume two transactions execute 
at the same time, each attempting to modify the same data.

So fields are automatically public static final.

Grim
  • 1,938
  • 10
  • 56
  • 123
  • This answer is complete and utter nonsense. Interfaces and transactions have exactly nothing to do with each other. – user207421 Feb 28 '18 at 01:30
  • @EJP I never said a interface is a transaction. I said one rule for interfaces is ACID. Not only in database-transactions. You think about database-transactions but there are more kind of transactions. – Grim Feb 28 '18 at 08:41