Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Platform type for public functions/properties #25

Open
voddan opened this issue Jun 21, 2016 · 3 comments
Open

Platform type for public functions/properties #25

voddan opened this issue Jun 21, 2016 · 3 comments

Comments

@voddan
Copy link

voddan commented Jun 21, 2016

A public function/method returning an expression of a platform type must declare its kotlin type explicitly:

fun apiCall(): String = MyJavaApi.getProperty("name")

Any property (package-level or class-level) initialised with an expression of a platform type must declare its kotlin type explicitly:

class Person {
    val name: String = MyJavaApi.getProperty("name")
}

A local value initialised with an expression of a platform type may or may not have a type declaration:

fun main(args: Array<String>) {
    val name = MyJavaApi.getProperty("name")
    println(name)
}
@voddan
Copy link
Author

voddan commented Jun 21, 2016

This is a follow up for KT-12310 Add inspection for methods with platform return type

I honestly don't know why having a kotlin method with type String! is allowed at all, but this proposal should level the inconvenience.

@cypressious
Copy link

You have a small typo in the title. Apart from that I obviously support this proposal.

@voddan voddan changed the title Pplatform type for public functions/properties Platform type for public functions/properties Jun 21, 2016
@kevinmost
Copy link

A local value initialised with an expression of a platform type may or may not have a type declaration:

Dunno that I like this. Just because the scope is smaller doesn't mean that the possibility of NPEs goes away. I personally think that platform types being treated as nullable without null-safe calls is the single biggest design mistake in the Kotlin language, so maybe my opinion here is overly strong, but I can't see why we would compromise null-safety for the sake of saving a few characters. =/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants