Skip to content

Convert to Kotlin #15

@veyndan

Description

@veyndan

Benefit A

Default values are still not supported in Moshi, yet Kotlin can support them natively. This means that List no longer needs to be nullable, with some obvious other examples being primitives.

Benefit B

Another benefit is that you access the Kotlin fields directly instead of having to use a getter.

Java

if (event.repo() != null) {
    event.repo().someFunction(); // Warning of calling method someFunction() on potentially null object
}

Kotlin

if (event.repo != null) {
     event.repo.someFunction(); // No warning occurs as nullability has been checked for
}

Benefit C

Java

event.repo().someFunction(); // Can cause NPE as event.repo() hasn't been checked for nullability

Kotlin

event.repo.someFunction(); // Would be a compiler error as event.repo hasn't been checked for nullability

Benefit D

Much more concise models in Kotlin, as builders, immutable objects, nullability status, are all extremely concise in Kotlin.

Benefit E

This isn't a huge benefit, but one less library (i.e. AutoValue) is used.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions