Skip to content

Conversation

alanleedev
Copy link
Contributor

Summary:
instead of explictly specifying fully qualified Java boxed types, use proper Kotlin syntax to refer to it.


👉 Notes on Java <> Kotlin type mapping !!!

See: Kotlin's Mapped Types; https://kotlinlang.org/docs/java-interop.html#mapped-types

  • kotlin Boolean maps to Java's primitive type boolean and not boxed Type Boolean
  • Java boxed type Boolean maps to Boolean? in Kotlin

So in Kotlin,

  • Boolean::class.java refers to Java primitive type Class<boolean> which is equivalent to Boolean::class.javaPrimitiveType
  • For boxed type use Boolean::class.javaObjectType == Class<Boolean>

TIP: When dealing with Java primitive types using reflection, use ::class.javaPrimtiveType or ::class.javaObjectType to avoid the confusion with using plain ::class.java.

Differential Revision: D73224138

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Summary:
instead of explictly specifying fully qualified Java boxed types, use proper Kotlin syntax to refer to it.


---
👉 Notes on Java <> Kotlin type mapping !!!

See: Kotlin's Mapped Types; https://kotlinlang.org/docs/java-interop.html#mapped-types
- kotlin `Boolean` maps to Java's primitive type `boolean` and not boxed Type `Boolean`
- Java boxed type `Boolean` maps to `Boolean?` in Kotlin


So in Kotlin,
- `Boolean::class.java` refers to Java primitive type `Class<boolean>` which is equivalent to `Boolean::class.javaPrimitiveType`
- For boxed type use `Boolean::class.javaObjectType` == `Class<Boolean>`

**TIP:** When dealing with Java primitive types using reflection, use `::class.javaPrimtiveType` or `::class.javaObjectType` to avoid the confusion with using plain `::class.java`.

Differential Revision: D73224138
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 17, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D73224138

@javache
Copy link
Member

javache commented Apr 23, 2025

Merged as 1fb04e2

@javache javache closed this Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants