Search code examples
javadefaultprivateaccess-specifier

Do not want to set private to default in Java


I have this in one class:

if (people.count < 10)
    return false;

But count is undermarked with red saying Change the visibility of count to default

count is in another class as private. But I don't want to change it to default. I know it is a bad practice. How can I make it work without setter and getters?


Solution

  • You can either change the visibility or expose a getter. Asking for another way to do this is literally asking, "how can I expose a variable without exposing it?" So, your call.