Avatar ·

¿Cómo reemplazar métodos estáticos de Java en Kotlin? Equivalente de static

¡Hola a todos! Acabo de empezar a migrar de Java a Kotlin y me encontré con un problema. En Java solía usar métodos estáticos para crear clases de utilidad o métodos de fábrica. Por ejemplo, esta simple clase en Java: ```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(); } } ``` Y los llamaba directamente por el nombre de la clase: `StringUtils.isEmpty(text)`. En Kotlin intenté escribir lo mismo: ```kotlin class StringUtils { fun isEmpty(str: String?): Boolean { return str == null || str.trim().isEmpty() } fun capitalize(str: String?): String? { if (isEmpty(str)) return str return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase() } }