使用 Kotlin 1.4-rc
.
对于此代码块:
try {
socket.getOutputStream().let {
it.write(bytes)
it.flush()
}
} catch (e: IOException) {
...
}
反编译结果为:try {
OutputStream var2 = this.socket.getOutputStream();
boolean var3 = false;
boolean var4 = false;
int var6 = false;
var2.write(bytes);
var2.flush();
} catch (IOException var7) {
...
}
那么,为什么是boolean var3 = false;
boolean var4 = false;
生成的,它们的目的是什么,因为它们没有被使用?
最佳答案
见评论 YouTrack here .
These booleans are used by debugger to determine whether we are inside inline function/lambda or not. Unfortunately, println is
@InlineOnly
, so, you would not see the names of the variables (@InlineOnly
functions do not have local variables table and linenumber info, although this is going to change). However, if you create your own inline function and then use it, you will variables like $i$f$ and $i$a$ in LVT (to see the LVT, pass -l flag to javap). The value of these variables is not important (always false, although it can be changed in the future), but range of these variables is what the debugger is looking at. If we are inside $i$f... range, we are inside inline function, if we are inside $i$a... range, we are inside inline lambda.
关于kotlin - 内联扩展函数 (let/run/also/...) 生成未使用的局部变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63246398/