kartikpatodi
04/08/2019, 3:02 PMkartikpatodi
04/08/2019, 3:07 PMCzar
04/08/2019, 3:09 PMinline fun <reified T> test(): Any {
return T::class.java
}
println(test<String>())
in the compiled code you'll see something like
Class var1 = String.class;
System.out.println(var1);
Czar
04/08/2019, 3:10 PMinline
functions.Czar
04/08/2019, 3:12 PMnewInstance
, yes it is more expensive than new Clazz()
kartikpatodi
04/08/2019, 3:14 PMnew T()
is there any way ither than reflection?
PS it is a java+Kt projCzar
04/08/2019, 3:17 PMmarstran
04/08/2019, 3:24 PMclass SomeClass<T>(
private val createT: () -> T
) {
fun create(): T = createT()
}
marstran
04/08/2019, 3:27 PMSomeClass<MyClass> { MyClass() }
kartikpatodi
04/08/2019, 3:27 PMn
instances inside the function but and i tried with reified but it is eventually creating Class
object in the bytecodemarstran
04/08/2019, 3:27 PMkartikpatodi
04/08/2019, 3:28 PMmarstran
04/08/2019, 3:29 PMmarstran
04/08/2019, 3:30 PMnew SomeClass<MyClass>(MyClass::new);
kartikpatodi
04/08/2019, 3:30 PMkartikpatodi
04/08/2019, 5:28 PMmarstran
04/08/2019, 5:54 PMkartikpatodi
04/08/2019, 6:15 PMkartikpatodi
04/08/2019, 6:16 PMmarstran
04/08/2019, 7:31 PM