KotlinPoet - 接口方法没有括号

KotlinPoet - No brackets for interface methods

我正在使用以下代码生成与 KotlinPoet 的接口

val funspec = FunSpec.builder("test").build()
val interfacespec = TypeSpec.interfaceBuilder("Test").addFunction(funspec).build()

这会生成以下代码:

interface Test {
      fun test() {
      }
}

函数test()有一个默认实现(有括号)。有没有办法去掉默认实现(去掉括号)?

Note that interface methods must always be ABSTRACT. The modifier is necessary when defining the interface... But these modifiers are omitted when the code is generated. These are the defaults so we don't need to include them for kotlinc's benefit!

所以只需将 .addModifiers(KModifier.ABSTRACT) 添加到您的 funspec