[JAVA] [Kotlin] 3 ways to get Class from KClass

The following three types are defined in KClass as properties that return Class.

Taking the ʻInt type of Kotlin` as an example, the returned contents are as follows.

.java .javaObjectType .javaPrimitiveType
Int::class int.class Integer.class int.class
Integer::class Integer.class Integer.class int.class
Other *.class *.class null

When to care

You will need to use them properly depending on whether you need to distinguish between primitive types and wrapper types. Also, I have followed the pattern of "Implementation that requires Class does not support primitive types ", so in such a case, it is necessary to call .javaObjectType.

Articles that I used as a reference

-[Kotlin 1 \ .0 Beta 4 changes -Qiita](https://qiita.com/mattak/items/ba0e3294d539a86f120f#%E3%81%95%E3%82%89%E3%81%AB% E3% 83% 8F% E3% 82% A4% E3% 83% A9% E3% 82% A4% E3% 83% 88)

Recommended Posts

[Kotlin] 3 ways to get Class from KClass
How to get Class from Element in Java
[Java] Get KClass in Java [Kotlin]
Get TypeElement and TypeMirror from Class
Kotlin Class to send to Java developers
Get "2-4, 7, 9" from [4, 7, 9, 2, 3]
Kotlin Class part.2 to send to Java developers
[IOS] How to get data from DynamoDB
Memo for migration from java to kotlin
Try to get data from database using MyBatis in Micronaut + Kotlin project
How to get keycloak credentials in interceptor class
Transform from a normal class to a lambda expression
How to get a heapdump from a Docker container
Migrate from Java to Server Side Kotlin + Spring-boot
[Android] Two ways to get a Bluetooth Adapter
How to get SIMD optimization from HotSpot JavaVM
Disassemble and decompile .class files compiled from Kotlin
[Java] Get KFunction from Method / Constructor in Java [Kotlin]
Pass Form class from Controller to Thymeleaf by Spring-Boot
[Ruby] Method to easily get the receiver type .class
Kotlin may take the world from App to Web
[Kotlin] How to get IP address and user agent
How to get jdk etc from oracle with cli
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Class to take count
Migrate from JUnit 4 to JUnit 5
From Java to Ruby !!
How to get the class name / method name running in Java
Generate JSON from JVM class files to see the hierarchy
Get to the abbreviations from 5 examples of iterating Java lists
[Java] Get Charset with Apathce Tika / Initialize String from Charset [Kotlin]
[IOS] How to get the table name from AWS DynamoDB
Get video information from Nikorepo and throw it to Slack
How to get the longest information from Twitter as of 12/12/2016
[Kotlin] Get Java Constructor / Method from KFunction and call it
[IOS14] How to get Data type image data directly from PHPickerViewController?
About smart cast in callback from Fragment to Activity in Kotlin