Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

But this is also achievable with static init methods on records and value classes, right?

  record Rational(int num, int denom) {
      Rational {
          int gcd = gcd(num, denom);
          num /= gcd;
          denom /= gcd;
      }
  }


How would you do the same thing with the late initialization of, say, a HashMap where you don't control the constructor?


Hmm, I see what you're saying -- yeah, this seems to be semantically identical to Kotlin's `lateinit` then


Exactly. AFAICT this will be optimized at the JVM level though, so once you've initialized the constant the JIT compiler can take full advantage of that fact.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: