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

203
Views
Kotlin - "run" for static Java methods

I have the following code:

import javax.swing.*
...
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName())
UIManager.put("ToolTip.border", BorderFactory.createEmptyBorder())
UIManager.put("PopupMenu.border", BorderFactory.createEmptyBorder())
...

I want to get rid of all UIManager. qualifiers, like this:

UIManager.run {
    setLookAndFeel(getCrossPlatformLookAndFeelClassName())
    put("ToolTip.border", BorderFactory.createEmptyBorder())
    put("PopupMenu.border", BorderFactory.createEmptyBorder())
    ...
}

Of course, this code doesn't compile. Is it possible to achieve?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you can use 'with' keyword to achieve that. This is one of the scoping functions in Kotlin.

with(UIManager)
{
    setLookAndFeel(getCrossPlatformLookAndFeelClassName())
    put("ToolTip.border", BorderFactory.createEmptyBorder())
    put("PopupMenu.border", BorderFactory.createEmptyBorder())
    ...
}

Ultimately you are expecting some sort of scoping function.This article gives detailed explanation about usecase for each scoping function in Kotlin. https://medium.com/@elye.project/mastering-kotlin-standard-functions-run-with-let-also-and-apply-9cd334b0ef84

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!