DEV Community

Discussion on: Android 12 gets a... Battery

Collapse
 
tkuenneth profile image
Thomas Künneth

I agree. Regarding trying hard to avoid null: maybe the InputDevice should have the hasBattery() method instead. Then the api flow would be:

if (inputDevice.hasBattery()) {
  val battery = inputDevice.getBattery()
Enter fullscreen mode Exit fullscreen mode

getBattery() might always be non-null, nonetheless. Just feel that query method should not be there :-)