Given the following code (which uses a dummy return but shows the issue):
import com.github.roookeee.datus.api.Datus
import com.github.roookeee.datus.api.Mapper
import com.github.roookeee.datus.immutable.ConstructorParameter
data class EntryDto(val id: Long?, val title: String, val content: String)
data class EntryEntity(val id: Long? = null, val title: String, val content: String) {
fun toDto(): EntryDto {
val mapper: Mapper<EntryEntity, EntryDto> = Datus.forTypes(this.javaClass, EntryDto::class.java)
.immutable(::EntryDto)
.from(EntryEntity::id).to(ConstructorParameter::bind)
.from(EntryEntity::title).to(ConstructorParameter::bind)
.from(EntryEntity::content).to(ConstructorParameter::bind)
.build()
return EntryDto(null, "", "")
}
}
Kotlin is not able to infer the correct generic types whereas Java >= 8 does (given two Java classes that are identical to the data classes here - two immutable object classes). I tried with the defaults for Kotlin 1.3.0 and -XXLanguage:+NewInference
but the later couldn’t even infer the right overload to pick for .immutable
.
Here is the datus dependency information to make the above code compile (nothing else is needed):
<dependency>
<groupId>com.github.roookeee</groupId>
<artifactId>datus</artifactId>
<version>1.3.0</version>
</dependency>
Am I missing something? datus makes heavy use of generics including self-recursive generic types (in AbstractConstructorBuilder
) so I can imagine it’s quite hard to infer, but this should not happen right? This makes datus unusable for kotlin atm
You can find datus sources here