Why make private inner class member public in Java?

前端 未结 7 2000
情深已故
情深已故 2020-12-02 15:54

What is the reason of declaring a member of a private inner class public in Java if it still can\'t be accessed outside of containing class? Or can it?

publi         


        
7条回答
  •  心在旅途
    2020-12-02 16:17

    I think you are missing the implementing the Iterator interface part in your sample code. In that case, you can't make the hasNext() method have any other visibility identifier other than public since that would end up reducing its visibility (interface methods have public visibility) and it won't compile.

提交回复
热议问题