Imagine some situation when we need to call some static method with arguments using :: in kotlin. Actually I can do it only with functions without param for example
Base64::hashCode
But when I try to use
Base64::encodeToString
Then I receive a warning that
Overload resolution ambiguity. All these functions match. public open fun encodeToString(input: ByteArray!, flags: Int): String! defined in android.util.Base64 public open fun encodeToString(input: ByteArray!, offset: Int, len: Int, flags: Int): String! defined in android.util.Base64
This form also aren't accepted by compiler
(Base64::encodeToString)( byteArrayOf(2), Base64.DEFAULT)
I wanted to mock this method using new feature of mockito as described here
Thanks for any information!
::operator is only use for the latter (so that you can pass the reference to something else which will use it). If you want to call the method, you do so just as you would in Java, with e.g.Base64.encodeToString(…). Or if you want a reference, I'd expect the context to allow it to be disambiguated — if not, perhaps you could post the surrounding code? - gidds