Hello, will we ever be able to declare multiple va...
# language-proposals
f
Hello, will we ever be able to declare multiple variables in a single statement like in Java? For example, would we be able to do this:
Copy code
// assigns variables x, y, z to integer value 5
val x, y, z = 5
// alternatively:
val x, val y, val z = 5
Or optionally, similarly to Python, we could declare them on a single line, but assign a different value to each of them:
Copy code
// the number of variables and assigned values would have to match (3 -> 3)
val x, y, z = 1, 2, 3
I understand that it might be hard to grasp at a first glance considering Kotlin has name based destructuring, but it could be useful in some scenarios
e
with (currently) experimental features - name-based destructuring and collection literals
Copy code
val [x, y, z] = [1, 2, 3]
❤️ 3
f
That's actually a neat approach, thanks
a
@ephemient in fact, if you want to be more explicit, you could o
Copy code
[val x, val y, val z] = [1, 2, 3]