Why the ctor?
Desoroxxx opened this issue · 4 comments
I am using the plugin with Groovy and Java, and the generated class has a private ctor, my question is why not remove the ctor?
Abuse of language sorry it should be clearer what I meant
gradle-buildconfig-plugin/demo-project/generic/build.gradle.kts
Lines 27 to 38 in d2d65f4
This is standard practice in the Java world. If a class only has static fields, then the class is meaningless when instantiated. These are called "utility classes". Checkstyle even has a rule to enforce hidden ctor: https://checkstyle.sourceforge.io/checks/design/hideutilityclassconstructor.html
Another real world example from a well-known library:
https://github.com/apache/commons-collections/blob/ac05d8fdbe62bbfe051e3b502e5f0fcfbba56c9b/src/main/java/org/apache/commons/collections4/ComparatorUtils.java#L47-L50
Note: if one deletes a private constructor, Java automagically generates a public zero-args constructor, see first sentence at Java specification: https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.9
Oh that makes sense I never thought about it this way, thanks