Java – cortlin: why can’t I do a task in the loop guard?
•
Java
Why is this syntax invalid? The error reported by IntelliJ is that only expressions are allowed in such a context (line 2) I wonder if there is any syntax to solve this problem, because Java allows this type of assignment in the loop function
var c: Int; while ((c = reader.read()) != 1) { }
Solution
Syntax is invalid because C = reader Read () is not an expression in kotlin – this prevents all = = vs = bugs
You must rewrite it to:
while (true) { val c = reader.read() if (c == 1) break ... }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码