public-members

Why make private inner class member public in Java?

∥☆過路亽.° 提交于 2019-11-27 18:45:36
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? public class DataStructure { // ... private class InnerEvenIterator { // ... public boolean hasNext() { // Why public? // ... } } } Gursel Koca If the InnerEvenIterator class does not extend any class or implement any interface, I think it is nonsense because no other class can access any instance of it. However, if it extends or implements any other non private class or interface, it makes sense. An example: interface EvenIterator { public

Why make private inner class member public in Java?

这一生的挚爱 提交于 2019-11-26 19:28:51
问题 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? public class DataStructure { // ... private class InnerEvenIterator { // ... public boolean hasNext() { // Why public? // ... } } } 回答1: If the InnerEvenIterator class does not extend any class or implement any interface, I think it is nonsense because no other class can access any instance of it. However, if it extends or implements any other