if est une expression en Kotlin – elle renvoie une valeur. Cela signifie que vous pouvez attribuer val result = if (cond) a else b. Les branches doivent être de types compatibles. when remplace les longues chaînes de if-else et est également une expression ; vous pouvez faire correspondre des constantes, des types ou utiliser des conditions arbitraires avec des gardes booléennes.

si comme expression
Full content is available with a subscription.
Get full access to all courses on the platform for one year with a single payment.
Unlike other platforms that charge per course, here you get everything for one price, and after one year of use there will be no automatic charge for the following year.