[Java] Get KFunction from Method / Constructor in Java [Kotlin]

things to do

Extract KFunction from Method / Constructor of Java.


You can do this by calling the following Method.kotlinFunction / Constructor <T> .kotlinFunction from Java.

Specifically, it is as follows.

KFunction<?> function = ReflectJvmMapping.getKotlinFunction(Foo.class.getConstructors()[0]);

important point

Since the generic type parameter is often not set to get the Method / Constructor from the Class, if you want to include the type parameter, you need to cast it in Java.

KFunction<Foo> function = ReflectJvmMapping.getKotlinFunction((Constructor<Foo>) Foo.class.getConstructors()[0]);

Articles that I used as a reference

Recommended Posts

[Java] Get KFunction from Method / Constructor in Java [Kotlin]
[Kotlin] Get Java Constructor / Method from KFunction and call it
[Java] Get KClass in Java [Kotlin]
Call Java method from JavaScript executed in Java
Get history from Zabbix server in Java
How to get Class from Element in Java
Get unixtime (seconds) from ZonedDateTime in Scala / Java
Call a method with a Kotlin callback block from Java
How to get the class name / method name running in Java
Get weather forecasts from Watson Weather Company Data in simple Java
Easily get an integer from a system property in Java
Get attributes and values from an XML file in Java
Automatic photo resizing method in Java
Get country from IP address (Java)
Get Null-safe Map values in Java
Java overload constructor starting from beginner
Get stuck in a Java primer
Call the super method in Java
Study Deep Learning from scratch in Java.
[Java] Pass arguments to constructor in Mockito / Set method default call to callRealMethod
Get the result of POST in Java
Java method
java (method)
[Kotlin] 3 ways to get Class from KClass
Get caller information from stack trace (java)
Concurrency Method in Java with basic example
Reverse Key from Value in Java Map
Using JavaScript from Java in Rhino 2021 version
[Java] Get tag information from music files
What is the main method in Java?
Try to get data from database using MyBatis in Micronaut + Kotlin project
Java method
Directory change monitoring method memo (Java, Kotlin)
Java constructor
How to get the date in java
[Java] method
What Java programmers find useful in Kotlin
[Java] Instance method, instance field, class method, class field, constructor summary
Element operation method in appium TIPS (Java)
Get "2-4, 7, 9" from [4, 7, 9, 2, 3]
[Java] Get MimeType from the contents of the file with Apathce Tika [Kotlin]
Get weather forecast from OpenWeatherMap in Rails
[Java] method
GetInstance () from a @Singleton class in Groovy from Java
[Java] Handling of JavaBeans in the method chain
I tried hitting a Java method from ABCL
Text extraction in Java from PDF with pdfbox-2.0.8
Method name of static factory method learned from Java 8
Library "OSHI" to get system information in Java
[Java] Get a random value from an array
[Deep Learning from scratch] in Java 3. Neural network
How to write Java String # getBytes in Kotlin?
Generate OffsetDateTime from Clock and LocalDateTime in Java
Get along with Java containers in Cloud Run
HMAC in Kotlin
[Android development] Get an image from the server in Java and set it in ImageView! !!
Partization in Java
Changes in Java 11
Java8 method reference
Rock-paper-scissors in Java
[Java] Get metadata from files with Apathce Tika, and get image / video width and height from metadata [Kotlin]