I have next java class:
public interface Callbacks {
void onImagePickerError(Exception e, Library.ImageSource source, int type);
void onImagePicked(File imageFile, Library.ImageSource source, int type);
void onCanceled(Library.ImageSource source, int type);
}
and next abstract class extended interface:
public abstract class DefaultCallback implements Callbacks {
@Override
public void onImagePickerError(Exception e, Library.ImageSource source, int type) {
}
@Override
public void onCanceled(Library.ImageSource source, int type) {
}
}
In my case need in one place extend this interface and use it when callback coming from outher library.
In my android kotlin code looks like this:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Library.handleActivityResult(requestCode, resultCode, data, this, callback)
}
private val callback = object: Library.Callbacks {
override fun onImagePicked(imageFile: File?, source: Library.ImageSource?, type: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onImagePickerError(e: Exception?, source: Library.ImageSource?, type: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onCanceled(source: Library.ImageSource?, type: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
It's nothing special. But in compile time i have error:
Error:(239, 28) Object is not abstract and does not implement abstract member public abstract fun onImagesPicked(@NonNull p0: (Mutable)List<File!>, p1: Library.ImageSource!, p2: Int): Unit defined in github.library.path.Library.Callbacks
Error:(240, 9) 'onImagePicked' overrides nothing
1) why error have incorrect method name - onImagesPicked
2) why this not compile?
I try this and it's worked!
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
Library.handleActivityResult(requestCode, resultCode, data, this, object: DefaultCallback() {
fun onImagePicked(imageFile: File?, source: Library.ImageSource?, type: Int) {
log("emm") //not worked and method useless
}
override fun onImagesPicked(p0: List<File>, p1: Library.ImageSource, p2: Int) {
photoFileUri = Uri.fromFile(p0[0])
setUpPhoto()
log("worked") //worked! how?
}
})
}
does not implement abstract member public abstract fun onImagesPicked(@NonNull p0: (Mutable)List<File!>, ...)- It seems the method should acceptListargument, but you declared aFileparameter:imageFile: File?.override fun onImagesPicked(p0: List<File>, ...), notoverride fun onImagesPicked(imageFile: File?, ...). That's why the method which logs"worked"works: it shares the same method signature as the method that is required, while youronImagesPicked(imageFile: File?, ...)does not match. You cannot simply change the parameter types & expect overriding to work.Callbacksinterface that Kotlin is seeing is not the sameCallbacksinterface you're seeing in your editor. Do you need to rebuild something? Maybe your pom/gradle.build is out of date? Some dependency somewhere may need to be fixed.