9
我想這個轉換Java代碼科特林:拋出異常的方法與科特林
public class HeaderInterceptor implements Interceptor {
@Override public Response intercept(Chain chain) throws IOException {
return null;
}
}
問題是,當我實現的方法,我得到的東西像
class JsonHeadersInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain?): Response? {
throw UnsupportedOperationException()
}
}
我發現在Kotlin中拋出異常的唯一信息是THIS。
從刪除問號的一部分,因爲它不是必要的,爲什麼它不以相同的方式處理IOException
?處理這種情況的最佳方法是什麼?
你是什麼意思「處理IOException」?所有異常都是Kotlin中的運行時異常,因此不需要在throws子句中聲明。實際上,即使Java代碼也不需要在其throws子句中聲明IOException,因爲它從不拋出任何IOException。 –