You are currently viewing Kotlin Generics Help Needed

Kotlin Generics Help Needed

Hi! I’m trying to create a


that accepts a

class parameter

and its print function prints the name of

provided class


class A<T>(val t: T) { fun print() { println(t!! } } class B {} fun main() { val b = B() A(b).print() }

The output is


But in this scenario, I had to construct


first, and then pass it as a parameter.

I don’t want this, I want my class to be modified to accept a


parameter instead so that I can run it like.

fun main() { A(B::class).print() }

submitted by /u/JuicyBeauty
[link] [comments]