ursus
10/27/2026, 11:58 PM@JvmInline
value class Percentage private constructor(val value: Int) {
companion object {
fun ???(value: Int): Percentage? =
if (value in 0..100) Percentage(value) else null
}
}
of ? create? rusty new?hfhbd
10/28/2026, 12:01 AMursus
10/28/2026, 12:01 AMinternal?hfhbd
10/28/2026, 12:03 AMursus
10/28/2026, 12:03 AMhfhbd
10/28/2026, 12:07 AMYoussef Shoaib [MOD]
10/28/2026, 12:13 AMoperator fun invoke, or if you want to maintain the private constructor but also have a top-level factory function, I do a companion internal fun construct or similar, then a top level function of the same nameursus
10/28/2026, 12:24 AMinvoke, I find it search is extremely slow for some reason, and unreliable at times, dont you? something is indexed differently than a normal function for sureursus
10/28/2026, 12:24 AMYoussef Shoaib [MOD]
10/28/2026, 12:29 AMinvoke is very implicit, so it has to search in strange placesursus
10/28/2026, 12:31 AMclass Foo : Function .. { override fun invoke
I cannot just cmd click on the invoke to find the callsite, that flat out doesnt workursus
10/28/2026, 12:31 AMEdgar Avuzi
10/28/2026, 12:45 AMursus
10/28/2026, 12:46 AMursus
10/28/2026, 12:47 AMursus
10/28/2026, 12:50 AMEdgar Avuzi
10/28/2026, 1:39 AMEdgar Avuzi
10/28/2026, 1:41 AMEdgar Avuzi
10/28/2026, 1:41 AMEdgar Avuzi
10/28/2026, 1:43 AMursus
10/28/2026, 2:22 AMAdam S
10/28/2026, 7:52 AMursus
10/28/2026, 10:56 AMYoussef Shoaib [MOD]
11/02/2026, 10:14 AMinternal + OptIn before to similar level of success tbh. All it takes is just finding usages of the opt-in.
But I agree, I'd use private constructor first, and only relax it to internal + OptIn if need be