https://kotlinlang.org logo
#dsl
Title
# dsl
m

Michael Friend

01/09/2020, 2:30 PM
I wrote a simple dsl with extension functions to build an object hierarchy for objects written in java. I want to use the
@DslMarker
annotation to limit the scope of the blocks but there doesn’t seem to be a way to do it without writing unnecessary builders (unneccessary since the java fields are mutable). Is there another solution to this or will I have to write builders to limit scope?
b

Brady Aiello

06/13/2020, 11:13 PM
It's a good idea to write builders anyway. Keeping models and builders separate helps when writing the actual functional part of your DSL. But one way to make your Java builders work for you in a Kotlin DSL is to make them extend a Kotlin abstract class that's annotated with your DSL annotation class. As long as your Java builder extends a Kotlin class or interface that's annotated with your annotation class, you should be good to go.
4 Views