How to pass Class.Companion as a parameter

41 Views Asked by At

I have a function that needs to receive a Class.Companion as a parameter and the way I'm receiving it is as Class only and not Class.Companion

        fun <T: Any> input(text: String, type: KClass<T>? = null): T {
            val scanner= Scanner(System.`in`)
            while (true){
                print(text)
                val result = convertToAppropriateType(scanner.nextLine()) as T
                if(type == null) return result
                if(result::class == type){
                    return result
                }
            }
        }

InputUtils.input("", String)

I tried it as T and Class

0

There are 0 best solutions below