如何覆盖 nativescript 中的重载 Java 方法?
How to override an overload Java method in nativescript?
我有一个 Android-Java class 有两个重载方法
package com.test;
public class A{
public void theMethod(Bitmap bitmap){
...
}
public void theMethod(int resource){
...
}
}
我正在尝试在 Nativescript-Angular 程序中扩展 class:
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'.
P.D。我没有 class com.test.A 代码。
在您的 tsconfig.json 文件中,您需要制作 --strictFunctionTypes:true.
"compilerOptions": {
"module": "commonjs",
"strictFunctionTypes": true,
"downlevelIteration": true
}
P.S. 如果您的参数计数在 Class A 中不同,则 Java 方法重载由开发人员通过显式检查来处理被调用函数的参数计数。
我有一个 Android-Java class 有两个重载方法
package com.test;
public class A{
public void theMethod(Bitmap bitmap){
...
}
public void theMethod(int resource){
...
}
}
我正在尝试在 Nativescript-Angular 程序中扩展 class:
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'.
P.D。我没有 class com.test.A 代码。
在您的 tsconfig.json 文件中,您需要制作 --strictFunctionTypes:true.
"compilerOptions": {
"module": "commonjs",
"strictFunctionTypes": true,
"downlevelIteration": true
}
P.S. 如果您的参数计数在 Class A 中不同,则 Java 方法重载由开发人员通过显式检查来处理被调用函数的参数计数。