#kt #歪点子 inline class 来了,const fun 就端上来罢🤓🤏 https://youtrack.jetbrains.com/issue/KT-14652
https://kotlinlang.org/docs/inline-classes.html
replies Andrey Breslav:
The main use-case is 'documentation'. See the resent example of discussion for "nameof" here: https://discuss.kotlinlang.org/t/nameof-to-get-names-of-program-elements/1518/4
https://github.dev/rust-lang/rust/tree/master/library/std
there are apparently 990 functions in their stdlib that have been converted as const fns
https://tech.youzan.com/java-metaprograming/ #learn 元编程是什么?为什么js人搞JSON不需要靠元编程?
编程,就是用SDK给的套路解决问题。
元编程,就是突破病态类型(仅编译期可见的静态类型) 的桎梏,编写能写代码的代码,即codegen函数,从而实现编译器没有自带的功能,例如打印“class指针”里的内容
☺️我有一个绝妙的点子替掉 https://square.github.io/kotlinpoet/ ,只是手里的屏幕有点小,写不下
https://github1s.com/bennyhuo/Kotlin-Trim-Indent/blob/master/trimindent-compiler/src/main/java/com/bennyhuo/kotlin/trimindent/compiler/TrimIndentIrGenerator.kt#L34-L81
瞄了一眼,发现截获覆盖字面量调用是挺简单的
https://kotlinlang.org/docs/inline-classes.html
const val x = encrypt("password")
const val hash = md5(File("config.file")
val routes = arrayOf(
get("/hello", (req, res) -> "Hello World");
get("/fizz", (req, res) -> "bazz");
);
dispatch(routes); //2* if
const val MEMORY_SIZE = 640.kb //fails now
const fun p(num: Int) = it == 0
typealias Zero = Int / ::p
//现在的带验证类型
value class Even(val num: Int) {
companion object {
operator fun contains(num: Int) = num % 2 == 0
}
}
& being able to use the return value of a constexpr function as an annotation
replies Andrey Breslav:
The main use-case is 'documentation'. See the resent example of discussion for "nameof" here: https://discuss.kotlinlang.org/t/nameof-to-get-names-of-program-elements/1518/4
https://github.dev/rust-lang/rust/tree/master/library/std
there are apparently 990 functions in their stdlib that have been converted as const fns
https://tech.youzan.com/java-metaprograming/ #learn 元编程是什么?为什么js人搞JSON不需要靠元编程?
编程,就是用SDK给的套路解决问题。
元编程,就是突破病态类型(仅编译期可见的静态类型) 的桎梏,编写能写代码的代码,即codegen函数,从而实现编译器没有自带的功能,例如打印“class指针”里的内容
☺️我有一个绝妙的点子替掉 https://square.github.io/kotlinpoet/ ,只是手里的屏幕有点小,写不下
https://github1s.com/bennyhuo/Kotlin-Trim-Indent/blob/master/trimindent-compiler/src/main/java/com/bennyhuo/kotlin/trimindent/compiler/TrimIndentIrGenerator.kt#L34-L81
瞄了一眼,发现截获覆盖字面量调用是挺简单的
YouTrack
Introduce constexpr/const modifier/annotation for functions that can be computed in compile-time : KT-14652
Introduce C++ style constexpr modifier (in Kotlin the better name might be const or it might be some @CompileTime annotation – to be designed). In short, functions marked with constexpr are verified by compiler to satisfy certain strict rules and they can…