我已经获得了这样的界面:
MyInterface {
List<FirebaseVisionFace> getFaceList();
}
我必须在类中实现它(我们称其为MyFirebaseFaceClass
),这样我们就可以做到
List<FirebaseVisionFace> faceList = myFirebaseFaceClass.getFaceList()
问题是要获得此面孔列表,需要以下内容:
Task<List<FirebaseVisionFace>> result =
detector.detectInImage(image)
.addOnSuccessListener(
new OnSuccessListener<List<FirebaseVisionFace>>() {
@Override
public void onSuccess(List<FirebaseVisionFace> faces) {
// Task completed successfully
// ...
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
// ...
}
});
是否可以在不将回调作为参数传递而使用回调获取列表的情况下实现此getFaceList()
方法?
Task<List<FirebaseVisionFace>> result =
detector.detectInImage(image)
.addOnSuccessListener((List<FirebaseVisionFace> faces) -> {
// Task completed successfully
})
.addOnFailureListener((@NotNull Exception e) -> {
// Task failed with an exception
})