Why doesn't Java allow private members in interface?

后端 未结 13 1373
时光取名叫无心
时光取名叫无心 2020-12-07 13:11

Why doesn\'t Java allow private members in interface? Is there any particular reason?

13条回答
  •  盖世英雄少女心
    2020-12-07 13:42

    From the Java Language Spec, (Access Control):

    "The Java programming language provides mechanisms for access control, to prevent the users of a package or class from depending on unnecessary details of the implementation of that package or class."

    Access control is all about hiding implementation details. An interface has no implementation to hide.

提交回复
热议问题