嗨,我是Kotlin世界的新手.我喜欢到目前为止所看到的并开始考虑将我们在Java应用程序中使用的一些库转换为Kotlin.
这些库充满了带有setter,getter和Builder类的Pojos.现在我用谷歌搜索了什么是在Kotlin中实施Builders的最佳方法,但没有成功.
第二次更新:问题是如何在Kotlin中使用一些参数为简单的pojo编写Builder设计模式?下面的代码是我尝试编写java代码然后使用eclipse-kotlin-plugin转换为Kotlin.
class Car private constructor(builder:Car.Builder) {
var model:String? = null
var year:Int = 0
init {
this.model = builder.model
this.year = builder.year
}
companion object Builder {
var model:String? = null
private set
var year:Int = 0
private set
fun model(model:String):Builder {
this.model = model
return this
}
fun year(year:Int):Builder {
this.year = year
return this
}
fun build():Car {
val car = Car(this)
return car
}
}
}
Run Code Online (Sandbox Code Playgroud) 在开发应用程序时,有时您希望支持许多不同的配置,因此您使用不同的配置文件.
这意味着每个配置文件都有一个属性文件application-a.properties,application-b.properties依此类推.
现在这些配置文件中的很多东西是相同的,有些东西是不同的.这会导致大量重复,并可能在以后导致问题.
有没有办法删除此属性重复?
尝试在HorizontalLayout中设置按钮时,该按钮倾向于与布局中其他组件的标题部分而不是组件本身对齐。例如
HorizontalLayout hl = new HorizontalLayout();
h1.addComponent(new TextField("Test");
h1.addComponent(new Button("Do Something");
Run Code Online (Sandbox Code Playgroud)
将导致按钮与文本字段不对齐,但与标题文本对齐。
如何修复对齐方式,使其与“文本字段”对齐?