Tag: 时髦

相当于Groovy的Kotlin spead-dot(*。)

鉴于下面的代码,以获得一个不错的列表中的所有帐户列表我必须执行以下操作: data class Customer(val accounts : List) data class Account(val number : String) fun getCustomers() = arrayListOf( Customer( arrayListOf(Account(“1”),Account(“2”)) ), Customer( arrayListOf(Account(“3”),Account(“4”)) ) ) fun main(args: Array) { // long println(getCustomers().map{ it.accounts }.flatten().map{ it.number }) // a little shorter (just discovered while typing the question) println(getCustomers().flatMap{ it.accounts }.map{ it.number }) 游乐场链接 在Groovy中,我可以这样做: println(getCustomers()*.accounts*.number.flatten()) // or […]

在Grails中可以使用Kotlin吗?

一些基本的事实导致我这个问题: Groovy具有完整的Java互操作性 Kotlin具有完整的Java互操作性 Kotlin也编译到Java 因此可以在Grails应用程序中编写Kotlin代码吗? 我在Grails 2.x上做了很多工作,最近在和Kotlin,Spring和Struts一起工作。 我真的很喜欢Kotlin的null-safety和type推理function,而Kotlin的function编程特性比Groovy更自然,更易于使用(最后一部分是纯粹的意见)。 是否有可能使用Grails来处理这样的事情: ORM 将请求映射到控制器/操作 JSP / GSP视图解析/呈现 而是使用Kotlin来编写域类,控制器动作,服务,对象工厂等的实际逻辑。 可能不太可能,因为我猜测Grails的一些核心function是通过动态输入实现的,但也许可以通过Gradle插件或直接的Grails插件来实现。 我喜欢Grails的convention-over-configuration范例提供的极端简单,但是我更喜欢Kotlin的静态types和types推断。 如果我可以在Grails环境中编写Kotlin的业务逻辑,对我来说,这将是最终的Web应用程序框架!