英文:
covert kotlin's Unit to Java's String
问题
public String BeaconValue() {
ProximityObserver proximityObserver =
new ProximityObserverBuilder(mContext, ((MyApplication) mContext).cloudCredentials)
.onError(new Function1<Throwable, Unit>() {
@Override
public Unit invoke(Throwable throwable) {
Log.e("desks", "proximity observer error: " + throwable);
return null;
}
})
.withBalancedPowerMode()
.build();
ProximityZone zone = new ProximityZoneBuilder()
.forTag("desks")
.inNearRange()
.onEnter(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext proximityZoneContext) {
NotificationsManager.this.beaconValue = proximityZoneContext.getAttachments().get("desk-owner");
return null;
}
})
.build();
proximityObserver.startObserving(zone);
return this.beaconValue;
}
// Getting the beacon attachment value string
public String getBeaconValue() {
beaconValue = BeaconValue();
return beaconValue;
}
英文:
public String BeaconValue() {
ProximityObserver proximityObserver =
new ProximityObserverBuilder(mContext, ((MyApplication) mContext).cloudCredentials)
.onError(new Function1<Throwable, Unit>() {
@Override
public Unit invoke(Throwable throwable) {
Log.e("desks", "proximity observer error: " + throwable);
return null;
}
})
.withBalancedPowerMode()
.build();
ProximityZone zone = new ProximityZoneBuilder()
.forTag("desks")
.inNearRange()
.onEnter(new Function1<ProximityZoneContext, Unit>() {
@Override
public Unit invoke(ProximityZoneContext proximityZoneContext) {
NotificationsManager.this.beaconValue = proximityZoneContext.getAttachments().get("desk-owner");
return null;;
}
})
.build();
proximityObserver.startObserving(zone);
return this.beaconValue;
}
// Getting the beacon attachment value string
public String getBeaconValue() {
beaconValue = BeaconValue(beaconValue);
return beaconValue;
}
so this is the code here, currently I have the Unit, but after some research, I found out that Unit is implicit so it does not need to return anything and it does not really return anything.
However, I want to return the beaconValue in this function, so I made this new function to get the implicit Unit from the beaconvalue function, it does not work. Wondering why.
(I have tried to change the Unit to String, but that is not the way it gives error. since on enter does not support String (Java))
Thank you.
updated.
答案1
得分: 0
这个方法返回 Unit
,因为你在 Function1
对象的返回类型上声明了它。如果 onEnter
函数允许任何类型,请将 Function1
声明中的类型更改为 <ProximityZoneBuilder, String>
。如果它特定需要 Unit
,那么你必须使用 Unit
。
英文:
The method returns Unit
because you have declared it as the return type on the Function1
object. Change the types in the Function1
declaration to<ProximityZoneBuilder, String>
if the onEnter
function allows for any type. If it specifically requires Unit
then you must use Unit
.
专注分享java语言的经验与见解,让所有开发者获益!
评论