Comment

Comment by kentosi

I haven't yet had the luxury to experiment with the latest version of Java, but this is one of the reasons why I wish Java introduced named parameters the say way kotlin and scala do.

Eg:

  data class Make(makeId: String, name: String)
  data class Model(modelId: String, name: String)

  data class Car(make: Make, model: Model, year: String, ...)
Now you can go ahead and order the params whichever way you wish so long as you're explicitly naming them:

  val v1 = Car(make = myMake1, model = myModel1, year = "2023", ...)
  val v1 = Car(model = myModel1, make = myMake1, year = "2023", ...)
parent kentosi 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton