Assignment not allowed in while expression?

前端 未结 5 843
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 06:28

In Java we can usually perform an assignment within the while condition. However Kotlin complains about it. So the following code does not compile:



        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 07:27

    (This Example for while loop ) Hope this example will help you..

    Change from

    while ((c = is.read(buffer)) > 0) { sb.append(String(buffer, 0, c, Charset.forName(UTF8))) }

    to

    while ({c = is.read(buffer);c}() > 0) { sb.append(String(buffer, 0, c, Charset.forName(UTF8))) }

提交回复
热议问题