Repository navigation
update: java interop page - #5875
Open
Danil Pavlov (danil-pavlov) wants to merge 5 commits into
Open
Danil Pavlov (danil-pavlov) wants to merge 5 commits into
Danil Pavlov (danil-pavlov) wants to merge 5 commits into
Conversation
Danil Pavlov (danil-pavlov)
marked this pull request as ready for review
October 21, 2026 15:52
Danil Pavlov (danil-pavlov)
requested a review
from Alexander Udalov (udalov)
October 21, 2026 15:59
Alexander Udalov (udalov)
requested changes
Oct 21, 2026
Danil Pavlov (danil-pavlov)
requested a review
from Alexander Udalov (udalov)
October 28, 2026 15:45
Alexander Udalov (udalov)
approved these changes
Oct 28, 2026
Co-authored-by: Alexander Udalov <udalov@users.noreply.github.com>
Dániel Csorba (daniCsorbaJB)
left a comment
Contributor
There was a problem hiding this comment.
Nice updates! I added a few comments and suggestions
| and Kotlin code can be used from Java as well. This page describes some details about calling Java code from Kotlin. | ||
|
|
||
| Pretty much all Java code can be used without any issues: | ||
| Most Java code can be used without additional configuration: |
Contributor
There was a problem hiding this comment.
we could remove passive from here:
You can use most Java code without additional configuration:
| val calendar = Calendar.getInstance() | ||
| if (calendar.firstDayOfWeek == Calendar.SUNDAY) { // call getFirstDayOfWeek() | ||
| calendar.firstDayOfWeek = Calendar.MONDAY // call setFirstDayOfWeek() | ||
| if (calendar.firstDayOfWeek == Calendar.SUNDAY) { // Call getFirstDayOfWeek() |
Contributor
There was a problem hiding this comment.
Suggested change
| if (calendar.firstDayOfWeek == Calendar.SUNDAY) { // Call getFirstDayOfWeek() | |
| if (calendar.firstDayOfWeek == Calendar.SUNDAY) { // Calls getFirstDayOfWeek() |
| if (calendar.firstDayOfWeek == Calendar.SUNDAY) { // call getFirstDayOfWeek() | ||
| calendar.firstDayOfWeek = Calendar.MONDAY // call setFirstDayOfWeek() | ||
| if (calendar.firstDayOfWeek == Calendar.SUNDAY) { // Call getFirstDayOfWeek() | ||
| calendar.firstDayOfWeek = Calendar.MONDAY // Call setFirstDayOfWeek() |
Contributor
There was a problem hiding this comment.
Suggested change
| calendar.firstDayOfWeek = Calendar.MONDAY // Call setFirstDayOfWeek() | |
| calendar.firstDayOfWeek = Calendar.MONDAY // Calls setFirstDayOfWeek() |
| } | ||
| if (!calendar.isLenient) { // call isLenient() | ||
| calendar.isLenient = true // call setLenient() | ||
| if (!calendar.isLenient) { // Call isLenient() |
Contributor
There was a problem hiding this comment.
Suggested change
| if (!calendar.isLenient) { // Call isLenient() | |
| if (!calendar.isLenient) { // Calls isLenient() |
| if (!calendar.isLenient) { // call isLenient() | ||
| calendar.isLenient = true // call setLenient() | ||
| if (!calendar.isLenient) { // Call isLenient() | ||
| calendar.isLenient = true // Call setLenient() |
Contributor
There was a problem hiding this comment.
Suggested change
| calendar.isLenient = true // Call setLenient() | |
| calendar.isLenient = true // Calls setLenient() |
| fun render(list: List<*>, to: Appendable) { | ||
| for (item in list) { | ||
| to.append(item.toString()) // Java would require us to catch IOException here | ||
| to.append(item.toString()) // Java would require catching IOException here because Appendable.append throws IOException |
Contributor
There was a problem hiding this comment.
Suggested change
| to.append(item.toString()) // Java would require catching IOException here because Appendable.append throws IOException | |
| to.append(item.toString()) // In Java, render() must catch or declare the IOException thrown by Appendable.append() |
| Java reflection works on Kotlin classes and vice versa. As mentioned above, you can use `instance::class.java`, | ||
| `ClassName::class.java` or `instance.javaClass` to enter Java reflection through `java.lang.Class`. | ||
| Do not use `ClassName.javaClass` for this purpose because it refers to `ClassName`'s companion object class, | ||
| Do not use `ClassName.javaClass` for this purpose because it refers to `ClassName`'s [companion object](object-declarations.md#companion-objects) class, |
Contributor
There was a problem hiding this comment.
Suggested change
| Do not use `ClassName.javaClass` for this purpose because it refers to `ClassName`'s [companion object](object-declarations.md#companion-objects) class, | |
| Don't use `ClassName.javaClass` for this purpose because it refers to `ClassName`'s [companion object](object-declarations.md#companion-objects) class, |
|
|
||
| According to Java's rules, `finalize()` must not be `private`. | ||
|
|
||
| > `finalize()` is deprecated in modern Java versions. Consider alternatives such as [`java.lang.ref.Cleaner`](https://docs.oracle.com/javase/9/docs/api/java/lang/ref/Cleaner.html) |
Contributor
There was a problem hiding this comment.
Suggested change
| > `finalize()` is deprecated in modern Java versions. Consider alternatives such as [`java.lang.ref.Cleaner`](https://docs.oracle.com/javase/9/docs/api/java/lang/ref/Cleaner.html) | |
| > The `finalize()` method is deprecated in modern Java versions. Consider alternatives such as [`java.lang.ref.Cleaner`](https://docs.oracle.com/javase/9/docs/api/java/lang/ref/Cleaner.html) |
| Other supported cases include acquiring a Java getter/setter method or a backing field for a Kotlin property, a `KProperty` for a Java field, a Java method or constructor for a `KFunction` and vice versa. | ||
|
|
||
| Other supported cases include acquiring a Java getter/setter method or a backing field for a Kotlin property, | ||
| a `KProperty` for a Java field, a Java method or constructor for a `KFunction` and vice versa. |
Contributor
There was a problem hiding this comment.
Suggested change
| a `KProperty` for a Java field, a Java method or constructor for a `KFunction` and vice versa. | |
| a `KProperty` for a Java field, a Java method or constructor for a `KFunction`, and a `KFunction` for a Java method or constructor. |
Contributor
There was a problem hiding this comment.
to remove latin
|
|
||
| > SAM conversions only work for interfaces, not for abstract classes, even if those also have just a single | ||
| abstract method. | ||
| > SAM conversions only work for interfaces, not for abstract classes, even if those also have just a single abstract method. |
Contributor
There was a problem hiding this comment.
Suggested change
| > SAM conversions only work for interfaces, not for abstract classes, even if those also have just a single abstract method. | |
| > SAM conversions only work for interfaces. They don’t apply to abstract classes, even when those classes have only one abstract method. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.