Skip to content

Use Java enums instead of static int #2

@xamino

Description

@xamino

Example of what I mean here.

Instead of using some defined static integers, you could just use a Java enumeration. This would allow code like here to be simplified to a nice switch statement for example. Additionally it will allow type checking at compile time and avoid unwanted double assignment of specific integer values (for example the classical copy & paste error).

Basically nitpicking, but I think it would improve the code readability and maintainability quite a bit.

EDIT: Ups, bad example. If you're using Java 8 though that if-else construct can still be switched out to be a simple switch statement, see here.

EDIT2: In case it is not clear: you could replace many of the static declarations in Constants.java with parameterized enums like shown here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions