Why doesn't Java allow private members in interface?

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

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

13条回答
  •  执念已碎
    2020-12-07 13:29

    private fields would not be completely useless as other fields and inner classes could access them.

    However private methods could not be implemented, even in nested classes, making them almost useless. You could read them using reflection, but that is rather an edge case.

提交回复
热议问题