karelpeeters
09/11/2017, 10:59 AMarrayOf(null)
is shorter.mike_shysh
09/11/2017, 11:01 AMval data = Array(customerInfoList.size) { arrayOf<CustomerInfo?>(null)}
mike_shysh
09/11/2017, 11:01 AMmike_shysh
09/11/2017, 11:01 AMBaron R
09/11/2017, 11:15 AMBaron R
09/11/2017, 11:16 AMjanvladimirmostert
09/11/2017, 12:24 PMinline fun blah(
flush: Boolean = false,
action: String = "Unknown",
account: Any? = null,
entities: MutableList<Any> = mutableListOf<Any>(),
f1: (em: EntityManager) -> MutableList<Any>? = { em -> mutableListOf<Any>() },
f2: (em: EntityManager) -> Unit = { em -> Unit }
): Result {
return Result( ... )
}
The f1 and f2 part doesn't compile
What I'm trying to accomplish here is to be able to do:
blah { em ->
// return nothing here
}
or
blah { em ->
mutableListOf("1", "2", "3")
}
So if you return nothing, f1 is executed, if you return a list, f2 is executedspand
09/11/2017, 12:27 PM= () { em ->
. Remove ()
kschlesselmann
09/11/2017, 12:51 PMlru.systemOptions.removeIf { option -> option.systemOptionId == systemOptionType.systemOptionId }
lru.systemOptions.add(systemOption)
and the option is added again with different values as before all other options of the set get deleted after lru = lruRepository.save(lru)
(save call to a Spring Data JPA repository). The returned value still contains them though … any ideas? lru.systemOptions
is the MutableSet here.Baron R
09/11/2017, 1:07 PMsealed class In<T>
data class InInt(val v: Int) : In<Int>()
data class InStr(val v: String) : In<String>()
sealed class Out<T>
data class OutInt(val v: Int) : Out<Int>()
data class OutStr(val v: String) : Out<String>()
fun <T> testTypeInference(i: In<T>) : Out<T> = when(i) {
is InInt -> OutInt(i.v + 1)
is InStr -> OutStr("Hello!" + i.v)
}
Baron R
09/11/2017, 1:08 PMi
is OutInt
in the first case of when
, then T
should already be bound to Int
right?Baron R
09/11/2017, 1:08 PMInferred type was OutInt but Out<T> was expected
even though OutInt
is an Out<T>
Baron R
09/11/2017, 1:10 PMkarelpeeters
09/11/2017, 1:10 PMT
. You can try filing a YouTrack issue.Baron R
09/11/2017, 1:11 PMkarelpeeters
09/11/2017, 1:12 PMas Out<T>
after the when expression.Baron R
09/11/2017, 1:12 PMkarelpeeters
09/11/2017, 1:13 PMBaron R
09/11/2017, 1:14 PMas Out<T>
here and then use another as OutInt
where I call this function?Baron R
09/11/2017, 1:15 PMkarelpeeters
09/11/2017, 1:16 PMjstuyts-squins
09/11/2017, 1:16 PMOut<T>
, so all clients will need to cast if they want an OutInt
or an OutString
mzgreen
09/11/2017, 1:20 PMinline fun <T,reified R: Out<T>> testTypeInference(i: In<T>) : R = when(i) {
is InInt -> OutInt(i.v + 1) as R
is InStr -> OutStr("Hello!" + i.v) as R
}
mzgreen
09/11/2017, 1:21 PMas R
out of when
like:
inline fun <T,reified R: Out<T>> testTypeInference(i: In<T>) : R = when(i) {
is InInt -> OutInt(i.v + 1)
is InStr -> OutStr("Hello!" + i.v)
} as R
Baron R
09/11/2017, 1:22 PMmzgreen
09/11/2017, 1:23 PMBaron R
09/11/2017, 1:24 PMOut<T>
right?mzgreen
09/11/2017, 1:24 PMmzgreen
09/11/2017, 1:25 PMmzgreen
09/11/2017, 1:26 PM