dan.the.man
01/05/2021, 5:13 PMfun getString(@StringRes resId: Int, vararg formatArg:Any) = activity()?.getString(resId, formatArg)
So I can call this instead of needing the context in every screen. But it doesn't correctly format, and it just displays lang.Object@zlkjdf
If I change the method to Java, it works though. Is some conversion going wrong from Kotlin to Java?tseisel
01/05/2021, 6:17 PMvararg Any
parameter is compiled into an Array<Any>
. That's the issue here: when passing the array to another vararg function, the array is passed as-is, hence the lang.Object
which is the string representation of the array in Java (not its content as a string!)
In such case, you need to spread that array:
getString(resId, *formatArg)
(mind the * !)dan.the.man
01/05/2021, 7:21 PM