Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"to" is an operator in the Kotlin stdlib #7

Open
stiffsteve opened this issue Feb 4, 2020 · 5 comments
Open

"to" is an operator in the Kotlin stdlib #7

stiffsteve opened this issue Feb 4, 2020 · 5 comments

Comments

@stiffsteve
Copy link

https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/to.html

This makes it difficult to use the to method from Kotlin because Kotlin interprets it as the stdlib operator.

@cketti
Copy link
Owner

cketti commented Feb 7, 2020

It doesn't feel like a big issue. You'd have to go out of your way to use that method instead of the one on EmailIntentBuilder. And then the IDE would show a warning that you're not using the infix calling syntax. And you couldn't use any of the other EmailIntentBuilder methods on the expression.

I can't think of another name for the method that is similarly short either. Do you have a suggestion?

@stiffsteve
Copy link
Author

Maybe I'm missing something obvious, but how would I use the EmailIntentBuilder without calling to to set the recipient?

@cketti
Copy link
Owner

cketti commented Feb 7, 2020

to from the stdlib is an extension function. Extension functions don't override existing methods. So the library's to method will be called (unless you provide an unsupported type as argument, then only the stdlib's to method is a match).

This is working fine for me (using Kotlin 1.3.61):

EmailIntentBuilder.from(requireActivity())
    .to("[email protected]")
    .cc("[email protected]")
    .bcc("[email protected]")
    .subject("Message from an app")
    .body("Some text here")
    .start()

@stiffsteve
Copy link
Author

It works fine with a literal, but since kotlin's to takes any type, it won't work with any var as the argument.

@stiffsteve
Copy link
Author

oddly enough, it's working for me on MacOS (Android Studio), but I can't get it to compile on LInux (also Android Studio)

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

No branches or pull requests

2 participants