Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

484
Views
Android and Kotlin varargs: formatted strings returns garbage

I'm encountering a strange problem: I've a general function which is used to retrieve resource strings (it's just to avoid writing context.resources.getString() everytime):

protected fun string(@StringRes stringRes: Int, vararg args: String): String = app.getString(stringRes, args) 

worked fine up until now, when I added the varargs to retrieve formatted strings. Simple strings still work fine but when I tried to retrieve a formatted one:

string(R.string.formatted_string, myId)

my string resource:

<string name="formatted_string">#%s</string>

I get some garbage:

#[Ljava.lang.String;@3a59711

expected:

#4848684

the garbage change with the resource I request

It looks a Object identifier.

If I don't use the method it works fine

What is happening here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The solution for you is to use the spread operator *:

fun string(@StringRes stringRes: Int, vararg args: String): String = getString(stringRes, *args)

Variable number of arguments (Varargs)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!