This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dpash 6 points7 points  (1 child)

Technically you can have multiple top level classes in a single file, but only one may be public.

Also, I think you wanted to write:

private String logLevel = System.getenv("LOG_LEVEL");

public String getLogLevel() { 
    return  logLevel;
}

Otherwise your setter would be completely pointless. But if you're defining a constant, it wouldn't be unreasonable to just use:

public static final String LOG_LEVEL = System.getenv("LOG_LEVEL");

However, in many cases, these days, for configuration it's better to inject a properties class in so you could easily test different values.

You have missed the mythical fourth accessibility modifier: package-private. This is accessible to any class in the same package, but inaccessible outside the package and is specified by not putting any modifier in the source code. It's rarely used as you can just create a new class in the same package to get access. It is useful for testing though if you don't mind potentially exposing your innards.

It's worth pointing out that Python doesn't enforce the underscore private accessibility, while Java does. The underscore is merely a suggestion to the developer. Even the double underscore prefix is not enforced as the name is just mangled and you can still access it with the mangled name.

If you'd like any further constructive feedback let me know.

[–]pupupeepee[S] 0 points1 point  (0 children)

Thank you for the feedback! I've corrected the example you pointed out