我有一些类似下面的Kotlin代码:
Thread {
...
Thread {
...
return@Thread
...
}.start()
...
}.start()
现在我得到以下警告:
I understand that kotlin is confused as to which Thread I want to return at this point, whether it's the outer or the inner thread. But I'm not sure how to tell it and Android Studio doesn't help much either, as it only suggests editing the options for this warning:
我try 过给线程命名,并认为kotlin可能足够聪明来判断它,但我猜这可能不可能,因为返回标签可能不会在运行时解释.
I realize that I can just export the inner thread into a function and thereby have the threads not interfere with each other, like this:
Thread {
...
startInnerThread()
...
}.start()
fun startInnerThread() {
Thread {
...
return@Thread
...
}.start()
}
But I would like to know if it's somehow possible to change the label @Thread
for one of them instead.