Montag, 10. Dezember 2012

Solution: “utility classes should not have a public or default constructor”

“utility classes should not have a public or default constructor”

If a class is static, you probably want to use its methods "directly" rather than instantiating it first. These kind of classes are more like tools/utilities than being meant for objects. Checkstyle warns you in this case that this class can still be instantiated. A little bit annoying for my liking ;)

Solution:

make the class final:
public final class myclass {
...
}

and create an empty private constructor:

private myclass() {
}

that should do the trick!

Keine Kommentare:

Kommentar veröffentlichen