4

How does Class<?> clazz look like in Kotlin ?

I'm trying to translate this method to Kotlin code and it seems like I'm stuck.

public static boolean isServiceRunning(Context context, Class<?> serviceClass) 
panagdu
  • 2,133
  • 1
  • 21
  • 36

2 Answers2

3
fun isServiceRunning(context: Context, serviceClass : Class<Any>) : Boolean 

something like that should do the job

Emanuel
  • 8,027
  • 2
  • 37
  • 56
2

You can define it as

companion object {
    fun isServiceRunning(context: Context, serviceClass: Class<*>): Boolean  { /* ... */ }
}

The Class<*> star-projection is almost equivalent to the Java unbounded wildcard Class<?>.

hotkey
  • 140,743
  • 39
  • 371
  • 326