Hello recently I come across a strange thing to me...
# getting-started
d
Hello recently I come across a strange thing to me. I declare a variable name with val and try to print it to the console the code look pretty much like this:
Copy code
fun main() {
	val cup = 25
	println(cup + " cup of water")
}
However this snippet of code face a compile error and the way to work around this is as follow:
Copy code
fun main() {
	val cup = 25
	println("" + cup + " cup of water")
}
I dont't know that in Java/Kotlin world this is normal or not but I think it's a little weird and can be improved to make a developer experience better (I come from JS field)
j
Probably you get an error because it's using
Int.plus
and passing a string to this function is not allowed. I would suggest using string templates instead:
Copy code
val cup = 25
println("$cup cups of water")
c
"can be improved to make a developer experience better" → yep, that's what string templates are for 🙂
d
Thank you for the standard practice. 😄
r
You should have used string Template " $cup
j
You added a space in front that wasn't there. Why is this better than the one I suggested?