Questions about Kotlin | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Questions about Kotlin

In this kotlin code, when we write map{it.toInt()} what is "map" and what is "it"? why is it also valid to write map{String :: toInt} ? ALSO, here we are able to assign values using userinput to 3 variables together using val (x, y, z) what is this feature called? is it available in java as well? https://code.sololearn.com/cTGNdP6IDs5d/?ref=app

30th Dec 2018, 7:30 PM
Asirap
15 Answers
+ 7
When we use function types we may also provide names for parameters, this further improves clarity of code: val sin: (angleInRadians: Double) -> Double = Math::sin Math::sin // method reference this is equivalent to { x -> Math.sin(x) } Function references in Kotlin: use functions as lambdas everywhere https://antonioleiva.com/function-references-kotlin/ Reference to a function ::happyNewYear // function reference happyNewYear( x ) // function call https://try.kotlinlang.org/#/Examples/Callable%20references/Reference%20to%20a%20function/Reference%20to%20a%20function.kt
31st Dec 2018, 3:37 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 9
Asirap Practice time! 😄💪😁👍 Function references in Kotlin: use functions as lambdas everywhere https://code.sololearn.com/cEVm894IJ93R/?ref=app
1st Jan 2019, 8:44 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
3rd Jan 2019, 7:10 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 6
https://code.sololearn.com/c02Vi9dPdVk4/?ref=app https://code.sololearn.com/c2ho07cgv097/?ref=app
30th Dec 2018, 10:43 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 6
Asirap 👍I'm glad, I knew you would understand, because I'm learning this way too! 🤓 It's not a problem, you can freely use everything you need, the codes are written to make it easier for us.💪 I have more useful codes, but when I find them, I'll let you know. Have a nice Coding my friend! ;)🍻
31st Dec 2018, 3:04 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 5
Asirap 😉 Gordon 💪 You are welcome! 😊 I will explain 👍 🙌Happy 🍾New year ...🎆 🍻
31st Dec 2018, 11:17 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
Basic tutorial about lambda, also by Danijel: https://code.sololearn.com/WNtO9vg0wvxE/?ref=app Best resource for learning Kotlin: Tutorial published by Danijel 👍👍👏👏🌄🌅🎆🎇🎆🎉🎊🎊 A catalog is here: https://code.sololearn.com/WKFF4vOCr3mi/?ref=app
31st Dec 2018, 9:10 AM
Gordon
Gordon - avatar
+ 2
Assigning multiple values in one statement like you showed is called destructuring. It's not possible to do it in Java, unfortunately.
8th Jan 2019, 5:46 AM
LunarCoffee
LunarCoffee - avatar
+ 1
thank you Danijel Ivanović . I did not know about lambdas in programming before, it's hard to wrap my head around it. What's the -> thing? Also can you please recommend any resources that would give me a very basic idea about lambdas and all?
31st Dec 2018, 9:01 AM
Asirap
+ 1
thank you! can you please explain the difference between map{it.toInt()} and map{String::toInt} and how they do the same thing? Danijel Ivanović Gordon
31st Dec 2018, 9:22 AM
Asirap
+ 1
Danijel Ivanović I've understood what -> is finally! thank you for making the codes. i've made a web code where I've included links to some of your codes as reference hope that's okay. Also can you kindly also explain my question in the comments about String::toInt please?
31st Dec 2018, 2:49 PM
Asirap
+ 1
thank you so much again! this is going to help me learn kotlin better and faster! Danijel Ivanović
31st Dec 2018, 4:00 PM
Asirap
3rd Jan 2019, 7:18 AM
Asirap
+ 1
LunarCoffee thank you! no one else answered that part of my question :D
8th Jan 2019, 9:18 AM
Asirap