nickk
05/09/2019, 2:50 PMObject
?
Say, I want a shorter name for Android’s `getString()`:
@NonNull
public final String getString(@StringRes int resId, Object... formatArgs) {
return getResources().getString(resId, formatArgs);
}
How do I write a Kotlin function that just forwards its arguments to this getString
?
According to the docs, I should use kotlin.Any!
Android Studio does not even let me add the !.
Using just vararg Any
results in IllegalFormatExceptions
streetsofboston
05/09/2019, 2:52 PM!
is a platform type. It comes in from Java. You can never define one yourself.
Have you tried the spread operator?
*formatArgs
? (note the *
)nickk
05/09/2019, 2:54 PMstreetsofboston
05/09/2019, 2:55 PMfun Resources.myGetString(id: Int, vararg arguments: Any) =
this.getString(id, *arguments)
Resources
is the Android Resources class defined in Java)nickk
05/09/2019, 2:59 PMlouiscad
05/09/2019, 4:28 PM