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 )
;
}