romainbsl
11/07/2017, 2:52 PMpublic class PersonJava {
private String name;
private String title;
// and so on...
}
class PersonJavaModel : ItemViewModel<PersonJava>() {
val name = bind { item?.observable(PersonJava::getName, PersonJava::setName) }
val title = bind { item?.observable(PersonJava::getTitle, PersonJava::setTitle) }
}
This works pretty well.
Now, I tried to do the same with a data class
data class PersonKotlin(var name: String? = null, var title: String? = null)
class PersonKotlinModel : ItemViewModel<PersonKotlin>() {
val name = bind { item?.observable(PersonKotlin::name) }
val title = bind { item?.observable(PersonKotlin::title) }
}
Here the bind function doesn't agree because my props are nullable.
But why does this work with POJOs ? they nullable too.
+ I tried to put the annotation @nullable on my POJO's props and this end with a compile exepction like with my data class, because my getters retrieve String? instead of String!, the type inference does its job here.
With my POJO I still can manipulate instances with null values in my UI and this works fine.
So why I cannot use nullable values with data classes and ItemViewModel ?