我有一个有两个重载方法的 Android-Java 类
package com.test;
public class A{
public void theMethod(Bitmap bitmap){
...
}
public void theMethod(int resource){
...
}
}
我正在尝试在 Nativescript-Angular 程序中扩展该类:
class ExtendedA extends com.test.A{
public theMethod(bitmap : android.graphics.Bitmap) : void{
...
}
}
但是我有这个错误
Property 'theMethod' in type 'ExtendedA' is not assignable to the same property in base type ‘A’.
Type ‘(bitmap : Bitmap) => void' is not assignable to type '{ (param: Bitmap): void; (param : number): void; }'.
Types of parameters 'bitmap' and 'param' are incompatible.
Type 'number' is not assignable to type 'Bitmap'.
PD我没有类 com.test.A 代码。
最佳答案
在您的 tsconfig.json 文件中,您需要制作 -- strictFunctionTypes:true .
"compilerOptions": {
"module": "commonjs",
"strictFunctionTypes": true,
"downlevelIteration": true
}
附注如果您的参数计数在 A 类中不同,则 Java 方法重载由开发人员通过显式检查调用函数的参数计数来处理。
关于java - 如何覆盖 nativescript 中的重载 Java 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54914187/