Tag: x rx kotlin

Rx Kotlin:map函数不能推断返回类型

在连接到蓝牙设备的应用程序中,我正在使用下面的函数使用RxKotlin: private fun startBluetoothPair(device: BluetoothDevice) { Observable.just(device) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .map { var uuid: UUID = BLUETOOTH_UUID var socket = it.createRfcommSocketToServiceRecord(uuid) socket.connect() return socket } .subscribe { // Do something with the BluetoothSocket } } 这个函数应该简单地连接到背景上的蓝牙设备,然后用套接字(再次在mainthread中)做一些事情。 然而, map无法处理return socket部分,告诉我有一个Type mismatch ,它发现一个BluetoothSocket它需要一个Unit 。 这里怎么了? 我认为地图应该能够推断返回类型。