Android/Kotlin

[문법] While문에서 assignment 불가능

lipnus 2018. 11. 25. 22:11
반응형



while ((c = inputStream!!.read()) != -1) {
outputStream.write(c)
}

이거 안되서 한참 고민. Kotlin은 while안에서 assign이 안된다.



do{
c = inputStream.read()
outputStream.write(c)
} while(c != -1)

이렇게 고치면 가능.






사람들은 이런 의견을 내고 있다.




The Kotlin team decided against it for a few reasons I think. In most cases it is just considered bad style and it also makes code harder to read. Yes your example is the one valid place where this kind of feature would be pretty handy, but they decided against it still, because only a small numbers of libraries would actually use something like this and it’s not worth adding an new feature to the language just for that.
Also there is a massive discussion about this here
























출처: https://discuss.kotlinlang.org/t/why-i-cant-apply-value-inside-while-loop/7762/2

반응형

'Android > Kotlin' 카테고리의 다른 글

WebView  (0) 2018.11.27
Jsoup  (0) 2018.11.26
kotlin기본 문법  (0) 2018.11.25
[Kotlin] HashMap  (0) 2018.11.24
[Kotlin] Retrofit  (0) 2018.11.24