Class Clazz in Kotlin

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) 

2 Answers

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

something like that should do the job

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<?>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest