https://kotlinlang.org logo
Title
e

efemoney

11/26/2018, 10:31 PM
I am getting started with using the kotlin-dsl in an android project and I’m a bit surprised that I have to use
buildTypes {
  getByName("debug") {
  ...
  }
}
instead of
buildTypes {
  "debug" {
  ...
  }
}
I can see a
NamedDomainObjectContainerScope
that defines the
String.invoke
extension but I’m not able to use it without explicitly specifying
buildTypes.invoke {
  "debug" {
  ...
  }
}
(possibly because the android plugin defines
fun buildTypes(Action<BuildType>)
). Is there a way to force the script to look like the second snippet above? (I believe Kotlin JVM had an annotation that would give the object extension more priority over the object member 🤔)
j

jmfayard

11/27/2018, 10:22 AM
The first syntax seems more "easy" for you because you are familiar with it, but I would argue that the second one is more "simple". Explicit is better than implicit