Big Chungus
04/07/2021, 9:46 AMuser
04/07/2021, 10:23 AMuser
04/07/2021, 10:36 AMDhanya S Pillai
04/07/2021, 11:45 AMToby
04/07/2021, 1:21 PMStanislav Karakovsky
04/07/2021, 3:12 PMthana
04/07/2021, 3:42 PMfun foo () {
val map: NavigableMap<String, String> = TreeMap()
map["key"] = null
}
Michael Böiers
04/07/2021, 4:03 PMimport java.util.*
fun compiles() {
val map: AbstractMap<String, String> = TreeMap()
map["key"] = null // non-null not enforced (platform type)
}
fun `does not compile` () {
val map = TreeMap<String, String>()
map["key"] = null // non-null enforced? Why? Isn't this also a platform type?
}
dave08
04/08/2021, 10:09 AMtrue
only if all functions return true
? (without putting them all on the same line... there's some code in between them)
var success = func1()
success = success && func2()
success = success && func3()
return success
Juke
04/08/2021, 12:14 PMJustin
04/09/2021, 3:19 PMeygraber
04/09/2021, 6:23 PMrunCatching
autocomplete to kotlin.runCatching
in the IDE? If I remove kotlin.
it still works fine.Richard Happe
04/09/2021, 7:38 PMsealed class SealedTypes {
companion object {
val types = setOf(One, Two, Three)
}
object One : SealedTypes()
object Two : SealedTypes()
object Three : SealedTypes()
}
class TypeContainer {
// Whichever type of SealedType this is set to is removed from the types set.
var theType: SealedTypes = One
}
And a test that doesn't really do much:
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun test() {
// uncomment this and the test will not crash
// SealedTypes.types
TypeContainer()
SealedTypes.types.forEach { acceptNonNull(it) }
}
fun acceptNonNull(value: SealedTypes) {
// no-op
}
}
test()
surprisingly crashes with a NullPointerException:
java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter value
at com.personal.ktbugtest.ExampleInstrumentedTest.acceptNonNull(Unknown Source:2)
at com.personal.ktbugtest.ExampleInstrumentedTest.test(ExampleInstrumentedTest.kt:20)
at java.lang.reflect.Method.invoke(Native Method)
...
Jason Jackson
04/09/2021, 8:21 PMelect
04/10/2021, 2:36 PMstable_partition
Move elements for which a predicate is true to the beginning
* of a sequence, preserving relative ordering.
george
04/10/2021, 4:02 PMRikin Marfatia
04/10/2021, 4:57 PMNthily
04/10/2021, 8:14 PMArpan Sarkar
04/11/2021, 1:12 PMjava.lang.ClassCastException: kotlin.Unit cannot be cast to kotlin.Result
when using useIR = true
Kotlin Version : 1.4.32
After upgrading to 1.4.32 all runCatching { }
call are throwing java.lang.ClassCastException
is there any bug or breaking changes in version 1.4.32 ?
As an example
suspend fun connect(clientId: String): Boolean {
if (isConnected) {
Timber.d("Already connected to broker ${mqttClient.serverURI}")
return true
}
mqttClient = MqttClient(BuildConfig.BROKER_URI, clientId, null)
mqttClient.setCallback(mqttCallback)
val result = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
runCatching {
Timber.d("Connecting to broker ${mqttClient.serverURI}")
val options = MqttConnectOptions().apply {
mqttVersion = MqttConnectOptions.MQTT_VERSION_3_1_1
isCleanSession = true
isAutomaticReconnect = true
maxReconnectDelay = 10000
}
mqttClient.connect(options)
Timber.d("Broker connected.")
}
}
result.exceptionOrNull()?.let { t ->
Timber.e(t, "Failed to connect to the broker.")
}
return result.isSuccess
}
Ananiya
04/11/2021, 4:02 PMkt
val thisIsATest = "**bold** normal **even bold** normal2"
"\\*\\*([\\s\\S]+?)\\*\\*(?!\\*)".toRegex().replace(thisIsTest,".").let{
println(it)
}
Is there any way to print like
bash
.bold. normal .even bold. normal2
Instead of [the output from the above code]
. normal . normal2
Grigorii Yurkov
04/11/2021, 4:52 PMequals
doc are not full?
Look at this code:
class MyClass {
override fun equals(other: Any?): Boolean {
return other != null
}
}
1. Reflexive: for any non-null value x, x.equals(x) should return true. ✅
2. Symmetric: for any non-null values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.✅
3. Transitive: for any non-null values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.✅
4. Consistent: for any non-null values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.✅
5. Never equal to null: for any non-null value x, x.equals(null) should return false.✅
But this code leads to the strange behavior:
println(MyClass() == Any()) // true
println(Any() == MyClass()) // false
Jonathan Mew
04/12/2021, 11:01 AMAndrew
04/12/2021, 2:17 PMsealed class Fruit
object Apple : Fruit()
object Banana : Fruit()
vs
sealed class Fruit {
object Apple : Fruit()
object Banana : Fruit()
}
Sudhir Singh Khanger
04/12/2021, 3:26 PMbuild-1.5.20-dev-5029
makes release page extremely noisy to follow Kotlin's Github release page via RSS.therealbluepandabear
04/13/2021, 12:06 AMnickheitz
04/13/2021, 8:53 AMMarian Schubert
04/13/2021, 11:06 AMYan Pujante
04/13/2021, 1:53 PMamirhosen.ebrahimi
04/13/2021, 3:52 PMalllex
04/13/2021, 7:56 PMclass Holder<out T>(val make: () -> T)
fun <T> Holder<T>.test(value: T) = check(value == make())
fun main() {
val h: Holder<Int> = Holder { 10 }
h.test("what?") // intuitively, should not compile
}
I would expect that this code does not type-check, because I am trying to compare Int
and String
.
However, in the call to test
, T
is inferred to Any
. Which actually allows you to pass any argument whatsoever, and it will compile.
The problem is that Holder
class is a library class, that I cannot modify. However, the test
function I can modify, but without changing its signature.
Is there a way to make the test
function check that T
is actually the same at the call-site without explicit typing? (h.test<Int>("what?")
)
P.S. Removing out
modifier from the Holder
signature solves the problem, but unfortunately, the Holder
class comes from a dependency.