How to replace static methods from Java with Kotlin? Equivalent of static
Hi everyone! I've just started transitioning from Java to Kotlin and encountered a problem. In Java, I often used static methods for utility classes or factory methods. For example, here's a simple Java class:
```java
public class StringUtils {
public static boolean isEmpty(String str) {
return str == null || str.trim().isEmpty();
}
public static String capitalize(String str) {
if (isEmpty(str)) return str;
return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
}
}
```
And I called them directly via the class name: `StringUtils.isEmpty(text)`. In Kotlin, I tried to write the same thing:
```kotlin
class StringUtils {
fun isEmpty(str: String?): Boolean {
return str == null || str.trim(
No answers yet.
Log in to leave an answer