Last active
May 21, 2017 09:16
-
-
Save DemoJameson/252999d3766efaa69a88e103785f1896 to your computer and use it in GitHub Desktop.
三元表达式的 Kotlin 实现,仅供娱乐
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias 布尔类型 = Boolean | |
fun main(vararg args: String) { | |
val 返回值 = ("42" == "真理") 问号 "是的,我看过《银河系漫游指南》" 冒号 "瞎扯啥" | |
println(返回值) // 瞎扯啥 | |
} | |
class 三块钱表达式<out 任意类型>(val 布尔值: 布尔类型, val 真值: 任意类型) | |
infix fun <任意类型> 布尔类型.问号(真值: 任意类型) = 三块钱表达式(this, 真值) | |
infix fun <任意类型> 三块钱表达式<任意类型>.冒号(假值: 任意类型) = if (布尔值) 真值 else 假值 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment