Slackbot
07/02/2021, 9:15 PMstandinga
07/03/2021, 12:52 AMfun Color.parseNullableColor(colorString: String?): Int? {
val colorString = colorString ?: return null
try {
return Color.parseColor(colorString)
} catch (e: IllegalArgumentException) {
return null
}
}
Seems it’s not possible? https://stackoverflow.com/questions/28210188/static-extension-methods-in-kotlin
Thanks!TwoClocks
07/03/2021, 9:24 PMif
that's being skipped, even though it evluates to true
in the debugger. I think it has to do w/ nullable types. There is a if statement above the one being skipped that under certin conditions will assign a instance to a nullable type. Then the second if statement checks some other conditions on that nullable type... but it looks like the compiler is just skipping the entire evluation of the second if
lesincs
07/04/2021, 9:31 AMmutableList.add(0,element),
are there any other APIs to insert an element to the head of a mutablelist
? mutableList.add(0,element)
is ok, but not as expressive. 🤔Slackbot
07/04/2021, 1:30 PMMaHDi
07/04/2021, 3:21 PMSam Garfinkel
07/04/2021, 4:48 PMJason5lee
07/05/2021, 2:52 AM.d.ts
.Slackbot
07/05/2021, 3:37 AMEmile Baccaini
07/05/2021, 1:17 PMCharlie L
07/06/2021, 1:09 AMSuspend function '..' should be called only from a coroutine or another suspend function
using IntellIJ? I can’t find any corresponding inspection in Code Cleanup, though I swear I automated this before…Noushad Chullian
07/06/2021, 6:15 AMSlackbot
07/06/2021, 6:28 AMpmatthews
07/06/2021, 9:45 AMGuilherme Gomes Correia
07/06/2021, 9:57 AMuser
07/06/2021, 5:42 PMjames
07/07/2021, 4:31 AMequals()
works or how kotlin.test.Assertions
might handle RuntimeExceptions
between Kotlin v1.3.62 and v1.5.20? I have a unit test that is more than a year old which started failing when I updated the version of Kotlin.
details:
I have a custom exception class, MyException:
internal class MyException(cause: Throwable) : RuntimeException(cause)
I then have some code which simply catches any errors and logs:
} catch (e: Exception) {
myLogger.logException(MyException(e))
}
Now inside the unit test, we want to confirm that we’re catching exceptions, transforming them to our type, and logging. So the exception is thrown and then log is checked as such:
val exception = RuntimeException("some failure!")
...
...
loggedExceptions.latest() shouldBeInstanceOf MyException::class
(loggedExceptions.latest() as MyException).cause shouldBeEqualTo exception
that final line now fails with the following:
java.lang.AssertionError: Expected <java.lang.RuntimeException: some failure!>, actual <java.lang.RuntimeException: some failure!>.
to reiterate, nothing about this unit test (or the class which it is testing) has changed in over a year. I can’t explain what could be happening here? would greatly appreciate it if someone could shine any light on this.
see attached the version diff:elect
07/07/2021, 7:56 AM-Xadd-modules=
, if running via Idea?user
07/07/2021, 11:33 AMJurriaan Mous
07/07/2021, 1:11 PMuser
07/07/2021, 4:08 PMIrene Serrano
07/07/2021, 7:48 PMif (hiddenView.getVisibility() == View.VISIBLE) {
TransitionManager.beginDelayedTransition(cardView, new AutoTransition());
hiddenView.setVisibility(View.GONE);
}
My code:
if (hiddenView.isVisible) {
TransitionManager.beginDelayedTransition(cardView, AutoTransition())
hiddenView.visibility = it.GONE
}
maarten ha
07/07/2021, 9:58 PMMartin Brehovsky
07/08/2021, 10:16 PMclass Foo<T: Any?> {
abstract fun returnValue(): T
abstract fun returnValueAsNonNullable(): T!! // this doesn't work
}
The problem is I need to define the T type as either nullable or non-nullable, but I'm trying to bridge semantics of reactive streams, which are always non-nullable and represent null
by empty stream state, and futures which are possibly nullable. However I need to differentiate between a nullable and non-nullable future, therefore decide whether to allow the reactive stream to return empty value (as null) or fail.Cyril Scetbon
07/09/2021, 4:41 AMexpecting an element
val res = api.getSObject("Account", "0015000000VALDtAAP").as(Account::class)
^
It seems there is an internal kotlin function/keyword as
that prevents me from calling that function on my class. For instance the class String can get the same error
>>> val x = "10"
>>> x.f1("ola")
error: unresolved reference: f1
x.f1("ola")
^
>>> x.as("ola")
error: expecting an element
x.as("ola")
^
I should get the same error but nope, any idea what’s going on ?Justin Tullgren
07/09/2021, 2:43 PM@JvmInline
annotation. Do i need to add a certain dependency?William Reed
07/09/2021, 7:40 PManiruddha dhamal
07/10/2021, 12:41 AMinterface DataProvider<T> {
fun provideData(t:T): Data
}
class TaxDataProvider: DataProvider<Tax> {
override fun provideData(t: Tax): Data {
return Data()
}
}
class Provider {
fun register(dataProvider: DataProvider<*>) {
dataProvider.provideData(Tax()) //Not able to call this. Getting error: Type mismatch Required Nothing. Found Tax
}
}
Is there any way to achieve this? I wanted to keep register method to accept type of DataProvider not specific type (TaxDataProvider).Gopal S Akshintala
07/11/2021, 5:16 AMPojo.class
) or any other way?SirNapkin1334
07/11/2021, 6:17 AMTODO()
and a short explanation of why it's unreachable, but is there a "better" way of doing it?SirNapkin1334
07/11/2021, 6:17 AMTODO()
and a short explanation of why it's unreachable, but is there a "better" way of doing it?rajesh
07/11/2021, 6:33 AMSirNapkin1334
07/11/2021, 6:36 AMFleshgrinder
07/11/2021, 6:46 AMunreachable
like we have it in Rust and the consensus with the Kotlin devs was that error("unreachable: description")
is good enough. Unlike Rust Kotlin doesn't need it to compile and adding it was perceived as adding unnecessary complexity.ephemient
07/11/2021, 7:12 AMunreachable()
, but they don't exist now (and the plan for exhaustive-when doesn't use it)Sourabh Rawat
07/11/2021, 8:42 AM