int a = 1, b = 2, c = 1;
if ((a = b) !=c){
System.out.print(true);
}
現在應該轉換爲科特林像
var a:Int? = 1
var b:Int? = 2
var c:Int? = 1
if ((a = b) != c)
print(true)
但它是不正確的。
這裏是我的錯誤:
in " (a=b)" Error:(99, 9) Kotlin: Assignments are not expressions, and only expressions are allowed in this context
其實上面的代碼只是爲了澄清該問題的例子。這是我原來的代碼:
fun readFile(path: String): Unit {
var input: InputStream = FileInputStream(path)
var string: String = ""
var tmp: Int = -1
var bytes: ByteArray = ByteArray(1024)
while((tmp=input.read(bytes))!=-1) { }
}
什麼錯誤(或錯誤),你好嗎? –
in「(a = b)」錯誤:(99,9)Kotlin:賦值不是表達式,只有表達式在此上下文中才允許使用 –