Pablo Schmid
04/19/2019, 11:08 PMPablo Schmid
04/19/2019, 11:19 PMit as Snapshot
to make ir work?Czar
04/19/2019, 11:46 PMOptional#map
, not Kotlin map
, this is because member method always takes preference over extension function with the same name and signature. Optional
happens to have map
method with the same signature as Kotlin map
, so the former is used.
As to why you need the cast, check what your snapshotRepo#save
returns.Pablo Schmid
04/19/2019, 11:52 PMorElse(null)
says “found nothing? requires Snapshot”Czar
04/19/2019, 11:58 PMsave
method?Pablo Schmid
04/20/2019, 12:00 AMCzar
04/20/2019, 12:01 AMPablo Schmid
04/20/2019, 12:02 AMorElse(null)
says “found nothing? requires Snapshot” (edited) . It’s a warningCzar
04/20/2019, 12:03 AMPablo Schmid
04/20/2019, 12:05 AMPablo Schmid
04/20/2019, 12:05 AMCzar
04/20/2019, 12:06 AMPablo Schmid
04/20/2019, 12:07 AMCzar
04/20/2019, 12:09 AMCzar
04/20/2019, 12:17 AMCzar
04/20/2019, 12:18 AMimport org.springframework.data.repository.CrudRepository
import java.util.*
fun main() {
lateinit var snapshotRepo: SnapshotRepo
fun setSnapshotName(snapshotId: UUID, name: String): Snapshot? {
val optional: Optional<Snapshot> = snapshotRepo.findById(snapshotId)
return optional
.map { it.name = name; snapshotRepo.save(it) }
.orElse(null)
}
setSnapshotName(UUID.randomUUID(), "Test")
}
interface SnapshotRepo : CrudRepository<Snapshot, UUID>
class Snapshot {
var name: String = ""
}
Pablo Schmid
04/20/2019, 3:00 AM