In Android Studio, the following code has the variable commandBytes
colored to indicate an "implicit anonymous class parameter":
public boolean writeCommand( byte[] commandBytes ) {
if( writeCommandInProgress.compareAndSet( false, true ) ) {
writeSubscription = bleDevice
.establishConnection( asBleServiceRef, false )
.flatMap( rxBleConnection -> rxBleConnection.writeCharacteristic( asInputCharId, commandBytes) )
.subscribe(
characteristicValue -> {
writeCommandInProgress.set( false );
if( !Arrays.equals( characteristicValue, commandBytes ) )
Log.d( LOG_TAG, "Data read back from writeCommand() doesn't match input");
},
throwable -> Log.d( LOG_TAG, "Error in writeCommand: " + commandBytes.toString() + "; " + throwable.getMessage() )
);
return true;
} else return false;
}
I can't figure out what this means. The description on JetBrains' help site isn't really helping: "That's a local variable which is used by an anonymous or local class inside the method and thus becomes a field of the anonymous class." How does this apply? Is it something I need to worry about?
The colouring indicates the parameter or local variable is declared outside and used inside an anonymous class (or lambda in this case). To make this possible the javac compiler will create a synthetic field in the anonymous class to store the variable in. You can see this by inspecting the bytecode (View > Show Bytecode
).
This is not something to worry about, it is not a warning, it's just a colouring of the syntax to provide information. It does mean the variable is implicitly or explicitly final, so it's not possible to reassign it without breaking compilation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With