小编Lit*_*pea的帖子

如何在 Dart/Flutter 中泛化可选参数

当我尝试创建一些接口并需要使用泛型来实现它们时,我遇到了问题。 我的问题是如何使用类似的无类型

Kotlin 中没有任何内容

Java 中无效

例子:

我有一个基类

abstract class Base<Out, In> {
  Future<Out> perform(In);
}
Run Code Online (Sandbox Code Playgroud)

我用的是正常情况,完美

class Download implements Base<bool, String> {

  @override
  Future<bool> perform(downloadUrl) async {
    // do download and return result here
  }
}
Run Code Online (Sandbox Code Playgroud)

在某些情况下,我不需要包含任何参数。但它需要 2 个泛型类型,所以我必须包含 void 作为输入

class DoSomething implements Base<bool, void> {

  @override
  Future<bool> perform(_) async {
    // do some thing here, no use the input parameter
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是,当在 DoSomething 类中调用执行函数时,它会将 void 视为与 Java 不同的函数类型,它需要一个输入参数,而不是什么都没有

DoSomething().perform((){});
Run Code Online (Sandbox Code Playgroud)

我不想在执行函数中包含任何参数。请给我任何处理此案的建议和解决方案。

generics android dart flutter

7
推荐指数
1
解决办法
1228
查看次数

Android BLE 特性 getValue 在 API 级别 33 中已弃用,我获取该值的正确方法是什么?

Android BLE 特性 getValue 在 API 级别 33 中已弃用,在developer.android中BluetoothGattCharacteristic表示我们可以使用BluetoothGatt#readCharacteristic(BluetoothGattCharacteristic)代替

但当我检查代码时,developer.android 也提到它返回一个布尔值而不是 byteArray BluetoothGatt#readCharacteristic(BluetoothGattCharacteristic)

我可以获得该值的正确方法是什么?

android bluetooth bluetooth-lowenergy

5
推荐指数
1
解决办法
2747
查看次数