Place private constructor to the class contains a top level function

I have the kotlin file with top level function and specified name for using it from java code:

Utility.kt

@file:JvmName("Utility")
package com.example

fun someUtilityFunc() {
    // ignored
}

and I can instantiate Utility class in my Java code:

Main.java

package com.example;

public Main {
    public static void main(String[] args) {
        new Utility();
    }
}

How can I add the private constructor to generated Utility class?

1 Like

Could you explain, why do you need it? I know that sometimes there is a convention to add a private constructor to utility classes in Java, but it is usually just for aesthetics. Why do you need this for kotlin code?

Because I use it from java code, and there is the coding standard in Java history for utility classes