.ifPresent() returns Unit in Kotlin
Hey I tried to use the reverse country code in Kotlin
and found out that the function ifPresent shown in the Read me only returns Kotlin.Unit
but with reverseGeocoder.getCountry(lat,lon).get() worked totaly fine.
is there a reason? Did I understand something wrong?
I've never used Kotlin before, but in Java Optional.ifPresent() is void method, i.e. a method that doesn't return anything. It seems reasonable that the method might return Kotlin.Unit when called from Kotlin if Kotlin is a language that always requires methods to return something.
ifPresent() takes a Consumer<Country> as an argument (that's what the country -> {...} code is in the example). My guess is that in Kotlin you should pass in a function with a signature like Country -> Unit as the argument. The function will be invoked only if the Country is present.