thomasnield
11/06/2018, 2:39 AMInt
that is a factor of 5
, I can't enforce this due to private constructor not being allowed?hudsonb
11/06/2018, 3:36 AMhudsonb
11/06/2018, 3:49 AMthomasnield
11/06/2018, 3:53 AMrobin
11/06/2018, 8:57 AMinit
block might do the trick, but that's also not allowed for inline classes... That's disappointing indeedlouiscad
11/06/2018, 10:34 AMhudsonb
11/09/2018, 2:56 PMUByte
I noticed they mark the constructor as internal, which isn't allowed normally, but is enabled via @Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
hudsonb
11/09/2018, 2:57 PM@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
inline class FactorOfFive internal constructor(internal val value: Int)
With a "construction extension" like this:
fun FactorOfFive(value: Int) = when {
value % 5 == 0 -> FactorOfFive(value)
else -> throw IllegalArgumentException("Value is not a factor of 5")
}
thomasnield
11/09/2018, 3:57 PM