E.Kisaragi
05/13/2020, 7:43 PMtypealias Nullable<T> = T?
(it's kinda useless, but I have to do similar one)Animesh Sahu
05/14/2020, 7:39 AMStefan Beyer
05/14/2020, 8:50 AMArray<Any?>
. There are helper methods that type juggle the return values like so:
fun Any?.toIntOrZero(): Int = (this as? Long)?.toInt() ?: (this as? Double)?.toInt() ?: 0
This is of course horrible, so I want to deprecate all of these helper functions, so that any developer sees that this is not the right way to do things:
@Deprecated("use the new type safe db repository instead of this manual type-juggling (see readme.md for refactoring advice)")
fun Any?.toIntOrZero(): Int = (this as? Long)?.toInt() ?: (this as? Double)?.toInt() ?: 0
But now there is a warning, that the replaceWith parameter of the deprecation annotation is missing. But there is no simple replacement of this, since every database access needs to be refactored and cleaned up individually. this helper function is just a symptom of the problem, so to speak. So is this ok, just to slap a @Suppress("DeprecatedCallableAddReplaceWith")
in front of this deprecation annotation and call it a day? Or is there a better way to do this?Jakub
05/14/2020, 1:34 PMó
-> o
ł
-> l
I can’t see in contains
function to ignore them.Gabriel Feo
05/15/2020, 11:10 AMrrva
05/15/2020, 1:03 PMString?
, what is idiomatic kotlin for it?Stephan Schroeder
05/15/2020, 3:49 PMfun main() {
listOf("yes", "no").filter(SomeClass::filterYes).forEach{
println(it)
}
}
class SomeClass {
companion object {
fun filterYes(str: String) = str == "yes"
}
}
but it doesn't. You can try it here: https://pl.kotl.in/sHlk5l7V0asad.awadia
05/15/2020, 4:28 PMKevin Gorham
05/15/2020, 5:30 PMif (error != null) throw error
egorand
05/15/2020, 6:09 PMPlease set environment variable JDK_16 to point to JDK 1.6 installation
Kotlin repo build failure on macOS Catalina?mathew murphy
05/15/2020, 6:23 PMHamza
05/16/2020, 9:40 AMKProperty<Type, Field>
, is it possible for me to get the specified field of Type
?
so like if we have
data class Foo(bar: String)
fun main() {
val foo = Foo("baz")
val whatWeWant = Foo::bar
println(foo.(whatWeWant)) // prints baz. unknown syntax
}
Merileoke
05/16/2020, 11:16 AMHanhnguyen Qcqa
05/16/2020, 11:19 AMSourabh Rawat
05/16/2020, 2:58 PMwhile (isalnum(LastChar = getchar())) {
IdentifierStr += LastChar;
}
taken from c++.Rodrigo Silva
05/16/2020, 5:31 PMchan
05/17/2020, 8:06 AMinspectClassesForKotlinIC
do for Kotlin in Gradle?Paul Woitaschek
05/17/2020, 9:42 AMregex.find(line)?.groupValues?.getOrNull(1)
Is this the correct way to find the first match of a regex result?Ofir Bar
05/17/2020, 4:41 PMtseisel
05/17/2020, 7:07 PMfor (n in 0.0..1.0 step 0.1)
I know that floating point numbers are imprecise and such a for loop should be avoided. Is this why there is no such construct ? Or are there any alternatives ?crummy
05/18/2020, 12:41 AMEither<>
class)turansky
05/18/2020, 9:39 AMcomponent0
compiled successfully.
How it can be used as operator on practice?
On playgroundBen
05/18/2020, 12:28 PMState state = State.Empty;
gives "expression expected". Am I missing something obvious?
sealed class State() {
object Empty : State()
...
}
jean
05/18/2020, 1:54 PMprivate val channel = Channel<Event>()
val events = flow { emit(channel.receive()) }
Use the channel inside a class to expose an api to emit values and receive those values else where as a flow?Philipp Mayer
05/18/2020, 4:08 PMwilliam
05/18/2020, 4:23 PMval a = Regex("foo")
a.replace("foobar", "\\w")
res3: kotlin.String = wbar
i would expect this to return \\wbar
- am I missing something here? Isn't \\
an escape for the \
?Adam Hurwitz
05/18/2020, 7:01 PMStateFlow
release developments?
I see there was a merge #1974 into the develop branch for StateFlow recently. After the develop branch is merged into master, does that mean StateFlow may be available in the next alpha/beta release?Rodrigo Silva
05/18/2020, 7:25 PMLeoColman
05/18/2020, 7:26 PMhashTwo = hashOne.map { (k, v ) -> k!! to v}
rrva
05/19/2020, 12:17 PMif (it.playables != null && it.playables.isNotEmpty())
Why does the compiler force me to write
if (it.playables != null && it.playables!!.isNotEmpty())
Due to the fact that
Smart cast to 'List<IdString>' is impossible, because 'it.playables' is a public API property declared in different module
rrva
05/19/2020, 12:17 PMif (it.playables != null && it.playables.isNotEmpty())
Why does the compiler force me to write
if (it.playables != null && it.playables!!.isNotEmpty())
Due to the fact that
Smart cast to 'List<IdString>' is impossible, because 'it.playables' is a public API property declared in different module
Desmond Teo
05/19/2020, 12:23 PMit.playables?.isNotEmpty() == true
streetsofboston
05/19/2020, 12:28 PMit
may have changed `it`’s nullable property playbable
to the value null just after the it.playables != null
check but before the it.playables.isNotEmpty()
call.rrva
05/19/2020, 12:30 PMstreetsofboston
05/19/2020, 12:31 PMrrva
05/19/2020, 12:33 PMstreetsofboston
05/19/2020, 12:35 PMit.playables?.let { … }
will do the trickMichael de Kaste
05/19/2020, 12:59 PMKroppeb
05/19/2020, 1:52 PMplayables
to be a var
instead of a val
, or a inconsistent custom getter, this piece of code would still work, as there is still a getter available. However now the guarantee that it.playables
is not null is no longer true.kqr
05/20/2020, 9:56 AM