sikri
11/26/2019, 10:43 AMlistOf(a, b, listOf(c, d).toTypedArray())
Even though, SpreadBuilder.addSpread
supports Collections and Iterators, based on this,
public void addSpread(Object container) {
...
else if (container instanceof Collection) {
list.addAll((Collection) container);
}
else if (container instanceof Iterable) {
for (Object element : (Iterable) container) {
list.add(element);
}
}
...
}
I cannot write code like this, even though it seems being supported:
listOf(a, b, listOf(c,d))
This leads to this in bytecode:
L41
LINENUMBER 154 L41
ALOAD 15
ICONST_0
ANEWARRAY pl/some/type
INVOKEINTERFACE java/util/Collection.toArray ([Ljava/lang/Object;)[Ljava/lang/Object; (itf)
L43
ASTORE 21
ALOAD 13
ALOAD 12
ALOAD 21
INVOKEVIRTUAL kotlin/jvm/internal/SpreadBuilder.addSpread (Ljava/lang/Object;)V
And as you can see, there is a useless array copyEugen Martynov
11/26/2019, 4:08 PMExecution failed for task ':common-i18n:compileDebugKotlin'.
> java.util.ConcurrentModificationException (no error message)
Janelle Fullen
11/26/2019, 10:16 PMuser
11/27/2019, 7:28 AMvpriscan
11/27/2019, 9:41 AMIve Vasiljevic
11/27/2019, 3:54 PMclass SomeClass1(private val property: Application)
and
class SomeClass2() {
private val property: Application? = null
}
I've noticed that in the second example of property declaration you HAVE to initialize property otherwise the compiler says that property needs to be abstract or initialized, but on the other hand in the first example initialization is optional.Jay M
11/28/2019, 11:03 AMMaurice Jouvet
11/28/2019, 12:43 PMJukka Siivonen
11/28/2019, 3:16 PMtransactionTemplate.execute {
val bar = doSomethingTransactional()
if (bar) {
{ doSomethingOutsideTransaction(bar) }
} else {
{ doSomethingElseOutsideTransaction() }
}
}?.invoke()
So that part of the code is run inside transaction and some part of code is run outside transaction (with data found inside transaction). Example is simplified a lot from real use case so bear with me.. :)df
11/28/2019, 4:00 PMfun createAddCartItemDto(
partnerId: Long = 29L,
productId: Long = 40L,
productVariantLabel: String = "A1",
testName: String? = null,
bucketGroup: String? = null
) = AddCartItemDto(
partnerId = partnerId,
productId = productId,
productVariantLabel = productVariantLabel,
bucketGroup = bucketGroup,
testName = testName
)
but i'm not the biggest fan of the duplicated parameter list .. better ideas?Ive Vasiljevic
11/28/2019, 4:16 PMJiri Bruchanov
11/28/2019, 6:10 PMval x = fun Int.() { this.toString() }
1.x()
can be 'x' defined as anonymous/named extension property ?
so I could have
1.x
?Daniel
11/28/2019, 7:05 PMsealed class TestClassParent(val any: Any) {
data class TestClassChild(val anyOther: Any) : TestClassParent(Any())
}
When I decompile this super.equals() seems to be not called in the TestClassChild:
public boolean equals(@Nullable Object var1) {
if (this != var1) {
if (var1 instanceof TestClassParent.TestClassChild) {
TestClassParent.TestClassChild var2 = (TestClassParent.TestClassChild)var1;
if (Intrinsics.areEqual(this.anyOther, var2.anyOther)) {
return true;
}
}
return false;
} else {
return true;
}
}
I don't know if you could construct a case where this matters, but at first glance it seems that the equals contract is broken
Daniel
11/28/2019, 7:07 PMSylvain Patenaude
11/28/2019, 9:04 PMdecodeToString
on it?Joey
11/29/2019, 1:28 AMsteenooo
11/29/2019, 9:12 AMJaymin.Kim
11/29/2019, 9:17 AMimport kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
fun main() = runBlocking {
sequence {
yield(10)
}.map {
foo() // ERROR: Suspension functions can be called only within coroutine body
}
Unit
}
suspend fun foo() = delay(1000L)
why this is not possible?molikuner
11/29/2019, 9:53 AMval a = "x"
val b = "x"
println(a === b)
This differs from the behaviour that I expected, as the following prints false:
val c = "X".toLowerCase()
println(a === c)
example code: https://pl.kotl.in/NTVgQNuWeSimon Craigie
11/29/2019, 4:55 PMfun <PARENT, CHILD: PARENT> returnFuncWithParentTypeAsParameter(resolver: (CHILD) -> Unit): (PARENT) -> Unit {
return resolver as (PARENT) -> Unit
}
Thanks in advance!Holger Steinhauer [Mod]
11/29/2019, 5:04 PMventura
11/29/2019, 5:07 PMkotlin.Result
programatically?Nir
11/29/2019, 6:36 PMmikehearn
11/29/2019, 6:39 PMa == b
to pass when a and b are of different types and may have fields that aren't included in the comparison?standinga
11/29/2019, 7:13 PMg4sarma
11/29/2019, 7:51 PMiex
11/30/2019, 12:11 PMursus
11/30/2019, 7:49 PMfun Message.diffUtilEquals(o: Any): Boolean {
if (o !is Message) return false
if (id != o.id) return false
return true
}
fun TextMessage.diffUtilEquals(o: Any): Boolean {
if (!super.diffUtilEquals(o)) return false
if (o !is TextMessage) return false
if (text != o.text) return false
return true
}
Hullaballoonatic
12/01/2019, 1:52 AMoperator fun Vector.times(scalar: Double) = mapToVector(scalar::times)
but since division isn't commutative, i can't use the same syntax for that, unless there's a way I don't know of?
operator fun Vector.div(divisor: Double) = mapToVector { it / divisor }
Marko Mitic
12/01/2019, 3:00 PMMap<A, B>
into Map<B, List<A>>
?Marko Mitic
12/01/2019, 3:00 PMMap<A, B>
into Map<B, List<A>>
?Map<A, List<B>>
into Map<B, List<A>>
Egor Babarykin
12/01/2019, 3:31 PMfun <A, B> Map<A, List<B>>.reverse(): Map<B, List<A>> = flatMap { it.value.map { v -> it.key to v } }
.groupBy({ it.second }, { it.first })