![]() ![]() Inlining a generic function with reified types But keep in mind that our function is also inlined. classĪt first glance, we still use Ljava/lang/Object like in the non-reified version. But the interesting part is here, where we get the class name of T. LOCALVARIABLE input Ljava/lang/Object L0 L2 0 INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String INVOKEINTERFACE kotlin/reflect/KClass.getQualifiedName ()Ljava/lang/String (itf) INVOKESTATIC kotlin/jvm/internal/Reflection.getOrCreateKotlinClass (Ljava/lang/Class )Lkotlin/reflect/KClass INVOKESTATIC kotlin/jvm/internal/Intrinsics.reifiedOperationMarker (ILjava/lang/String )V INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String )Ljava/lang/StringBuilder public final static synthetic getInfoFix(Ljava/lang/Object )Ljava/lang/String Let’s take a look at the bytecode of the getInfoFix function above (again, your line number might be different). $"Type of is: "Īnd it also works as we expected. Below is a simple generic method to print the name of the type used as argument. In C#, we can create a Type instance of a generic type with the typeof keyword. What is type erasure? C# allows us to access type information at runtime Today, we will take a look at type erasure and reified in Kotlin. NET, the way Kotlin handles type information at runtime surprised me. As a relatively new language, Kotlin also supports generic typing. ![]() Generic is a common feature in modern programming languages. Note: phiên bản Tiếng Việt của bài này ở link dưới. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |