我想在实现接口的类中使用函数参数的默认值,如下所示:
interface FileStoreService {
fun storeFile(path: String, payload: InputStream, type: MediaType, replace: Boolean = true)
}
Run Code Online (Sandbox Code Playgroud)
class LocalFileStoreService : FileStoreService {
override fun storeFile(path: String, payload: InputStream, type: MediaType, replace: Boolean /* ?? */) {
// ....
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这是编译的内容,这是未编译的内容:
KO:不允许重写函数为其参数指定默认值
class LocalFileStoreService : FileStoreService {
override fun storeFile(path: String, payload: InputStream, type: MediaType, replace: Boolean = true) {
// ....
}
}
Run Code Online (Sandbox Code Playgroud)
KO:“LocalFileStoreService”类不是抽象的,也没有实现抽象成员 public Abstract fun storeFile(path: String, Payload: InputStream, type: MediaType): 在 fqn...FileStoreService 中定义的单元
class LocalFileStoreService …Run Code Online (Sandbox Code Playgroud) kotlin ×1