In Java, we can create an utilities class like this:
final class Utils {
public static boolean foo() {
return false;
}
}
Bu
The last solution you've proposed is actually quite idiomatic in Kotlin - there's no need to scope your function inside anything, top level functions are just fine to use for utilities, in fact, that's what most of the standard library consists of.
You've used the @JvmName
annotation the right way too, that's exactly how you're supposed to make these top level functions easily callable for Java users.
Note that you only need @JvmMultifileClass
if you are putting your top level functions in different files but still want them to end up grouped in the same class file (again, only for Java users). If you only have one file, or you're giving different names per file, you don't need this annotation.
If for some reason you want the same Utils.foo()
syntax in both Java and Kotlin, the solution with an object
and then @JvmStatic
per method is the way to do that, as already shown by @marianosimone in this answer.