Acording to intellij and gradle, this variable a
type is Deferred<{Comparable & java.io.Serializable}>
:
val a = async(IO) { possibleIdDeferred.await()?.also { repo.findAttrById(it) } ?: run { "" } }
where possibleIdDeferred
is Deferred<Long?>
and this is the repo function:
@Cacheable("someCacheName")
suspend fun findAttrById(id: Long) = entityRepo.findById(id)!!.someAttr
where entityRepo
declaration is
@Repository
interface EntityRepo : CoroutineCrudRepository<Entity, Long> {
suspend fun findByAttr(attr: String): Entity?
}
If I add as String
as here:
val a = async(IO) { possibleIdDeferred.await()?.also { repo.findAttrById(it) as String} ?: run { "" as String} }
I get [USELESS_CAST] No cast needed
. If I try a.await() as String
I get [CAST_NEVER_SUCCEEDS] This cast can never succeed
. What should I change to make variable a
type String?