java - 如何覆盖 nativescript 中的重载 Java 方法?

标签 java android nativescript nativescript-angular

我有一个有两个重载方法的 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/

相关文章:

java - 高级客户端 JAX-WS 配置

java - 为什么我的程序创建空的 .lck 文件?

javascript - 如何在android上制作模糊图像? react native

android - ListView 中的 EditText 在 ListView 中滚动时丢失内容

angular - 奇怪的 NativeScript/Angular2 问题,应用程序在错误的位置查找模板

javascript - NativeScript 中的自定义对话框

java - 使用 itext pdf stamper 在 pdf 中添加多个附件

java - 0% 代码覆盖 jacoco4sbt 2.0.0, sbt 0.12.2

android - 如何用 rxjava2 取消 Observable.timer?

android - 如何使用 NativeScript 收听传入的短信?