Kotlin JPA:如何处理@OneToOne初始化
在Java中,我是这样做的:
public class User { //one-to-one private Profile profile = new Profile(this); } public class Profile { private User user; public Profile(User user) { user.setProfile(this); this.user = user; } }
所以我只是创建一个用户和配置文件自动创建。 现在我不明白如何用Kotlin的主要构造函数来做到这一点:
class User( var profile: Profile = Profile(this) //error, since `this` is not in that context ) class Profile ( var user: User? ) { constructor(user: User): this(user) }
你将如何处理这个?
这工作:
class User { var profile = Profile(this) } class Profile(var user: User?) { }
- Kotlinx-html ref事件
- 如何解决Kotlin(no lambda)中的重载解析歧义?
- Kotlin如果不是空的
- 如何使用Hibernate将UUID共享为两个表中的主键?
- 什么是Kotlin中的generateStubs配置?
- Android Studio 3.0未解决的参考:SupportedLanguages for AIConfiguration类在Dialogflow(api.ai)
- 如何在Kotlin中使用Gson的TypeToken +泛型
- Android中的布局参数动画性能低下
- Android Kotlin创建类实现Parcelable在writeToParcel方法的“覆盖”中给出一个错误