0

Android Studio informs me that the following Lambda can be converted into a Method Reference:

        result -> result.getBleDevice()

But when I try, I get an error:

        RxBleScanResult::getBleDevice

The result parameter is of type RxBleScanResult, but I get the error "Non-static method cannot be referenced from a static context". The code resides in a static method, but result is an object instance, in the class that defines the getBleDevice() method.

I've tried to understand the discussion of "reference to an instance method of an arbitrary object of a particular type" but I don't see why this won't work, when the Lambda version is acceptable.

Update: here's the entire method (see the last 2 lines):

static Observable<RxBleDevice> getScanObservable( UUID serviceUUID ) {
    return GlucometerApplication.getRxBleClient()
            .scanBleDevices(
                    new ScanSettings.Builder()
                            .setScanMode( SCAN_MODE )
                            //.setMatchMode( MATCH_MODE )
                            .build(),
                    new ScanFilter.Builder()
                            .setServiceUuid( new ParcelUuid( serviceUUID ) )
                            .build()
            )
            //.map( result -> result.getBleDevice() )
            .map( RxBleScanResult::getBleDevice )
            ;
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
Robert Lewis
  • 1,847
  • 2
  • 18
  • 43
  • 1
    How is `getBleDevice` defined? – Joe C Nov 04 '17 at 20:31
  • `scanBleDevices` emits `RxBleScanResult` objects. These have an instance method `public RxBleDevice getBleDevice()` – Robert Lewis Nov 04 '17 at 21:29
  • That `scanBleDevices` method [returns](https://github.com/Polidea/RxAndroidBle/blob/fbd41758ed48e82f0a2d6b13ed066cea963c72b2/rxandroidble/src/main/java/com/polidea/rxandroidble/RxBleClient.java#L120) `ScanResult`, not `RxBleScanResult`. – akarnokd Nov 04 '17 at 21:52
  • Bingo! @akarnokd! WTH, I have used that library quite a bit and I don't remember a separate type of ScanResult. – Robert Lewis Nov 04 '17 at 22:54

0 Answers0