Why does Android Studio convert some primitive Kotlin types as a conditionally safe statement?

I know that here I should not ask “why”, but I hope this is one of the allowed exceptions, as this is a code related issue. I do not yet know the consequences of this new language.

I am using Android studio 3.0 canary 3 and I am converting Java code to Kotlin. Most of the code is converted manually, but some other code I convert it by copying / pasting java into a new Kotlin file.

So far so good. However, I began to notice this:

Java Code:

class MyClass {
    private String userId;
    private Long newFolderId;
    private int oldFolderId;

    public MyClass(final String userId, final Long newFolderId, final int oldFolderId) {
        this.userId = userId;
        this.newFolderId = newFolderId;
        this.oldFolderId = oldFolderId;
    }
}

I will copy this small piece of code into Kotlin, and it will automatically convert to this:

class MyClass(private val userId: String, 
              private val newFolderId: Long?, 
              private val oldFolderId: Int)

So my question in this question is why it Longconverts toLong?

, ?? , String? Int?

Long?

, , , ? Long Long?

.

+4
1

, ?

- - Kotlin - JVM, . Kotlin

- - , Java- Kotlin. , Java , .

Java Long , . Java Long Long.

, Long Java, nullable Long?. int Java - null - non-nullable int

Java

class MyClass {
    private String userId;
    private long newFolderId;
    private int oldFolderId;

    public MyClass(final String userId, final long newFolderId, final int oldFolderId) {
        this.userId = userId;
        this.newFolderId = newFolderId;
        this.oldFolderId = oldFolderId;
    }
}

internal inner class MyClass(private val userId: String, private val newFolderId: Long, private val oldFolderId: Int)

, Long -nullable Long


String -nullable?

- , , .

String , - . . String NULL. , , String .


. , , , , NULL. Long Long?, .

+2

Source: https://habr.com/ru/post/1679072/


All Articles