Marc Knaup
12/06/2018, 5:52 PMjava.lang.ClassCastException: service.CityName cannot be cast to java.lang.String
in Kotlin 1.3.10 with inline classes.
I heard this is resolved but that Kotlin update isn't released yet.
When will it be released? Or can I use the dev build with Gradle somehow? 🙂Marc Knaup
12/06/2018, 6:59 PMMarc Knaup
12/06/2018, 7:15 PMinline class
instance returned by a generic (reified
) function directly to a variable captured by a lambda seems to be problematic.crummy
12/06/2018, 10:04 PMList<KClass<? extends Event>>
I can't figure out what the right syntax for this is though, can someone help?crummy
12/07/2018, 12:23 AMclass EventManager{
private val listeners: MutableMap<KClass<out Event>, MutableList<EventListener<in Event>>> = HashMap()
fun <T : Event> register(event: KClass<out T>, listener: EventListener<T>) {
val eventListeners: MutableList<EventListener<T>> = listeners.getOrPut(event) { ArrayList() }
eventListeners.add(listener)
}
fun notify(event: Event) {
listeners[event::class]?.forEach { it.handle(event) }
}
}
My getOrPut
call wants a MutableList<EventListener<T>>
but found MutableList<EventListener<in Event>>
instead.chansek
12/07/2018, 9:34 AMrocketraman
12/07/2018, 3:55 PMpublic fun
to public inline fun
binary and source compatible?Casey Brooks
12/07/2018, 4:00 PMGokhan Alıcı
12/07/2018, 5:28 PMkarelpeeters
12/07/2018, 5:40 PMTravis Griggs
12/07/2018, 7:14 PMthis
. For the grins of it (because sometimes silly ideas lead to better understanding), I thought I’d try something like this:
val <Receiver>Receiver.self: Receiver get() = this
It works pretty well. I can now use self
in lieu of this
. Except in a few cases. One such case is in an init
block:
private val manager:DownloadManager
init {
self.manager = self.context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
}
It will not allow the self.manager
reference there. It’s OK with the self.context...
. And I can use just manager
or this.manager
, but for some reason my “selfish substitution” does not work there.
Enlighten me?william
12/08/2018, 4:22 PMbenleggiero
12/08/2018, 6:08 PMsp33dy
12/08/2018, 6:38 PMketurn
12/08/2018, 10:13 PMfun isBetween(x, edge1, edge2): Boolean = x in (edge1 .. edge2)
but that doesn't Do What I Mean because 5 in (10 .. 1)
is false.
Is there anything in the standard library that handles this already, or do I have to add an if edge2 < edge1
in there to make sure they're the right way around?DJ2
12/08/2018, 11:05 PMfindViewById
is no longer necessary,
val btnSaveClick= findViewById<Button>(R.id.btnSave)
btnSaveClick?.setOnClickListener {
Toast.makeText(this@ArticleAdapter, "Article saved.", Toast.LENGTH_LONG).show()
}
What should be used insteadDico
12/09/2018, 12:28 AMkenji_otsuka
12/09/2018, 8:46 AMkarelpeeters
12/09/2018, 9:25 AMV
, an type not known at compile time?Pere Casafont
12/09/2018, 10:51 AMopen class ParentFoo
class ChildFoo : ParentFoo()
abstract class ParentBar {
open var foo: ParentFoo? = null
}
class ChildBar : ParentBar() {
override var foo: ChildFoo?
get() = super.foo as ChildFoo?
set(value) {
super.foo = value
}
}
right now I'm not allowed to set ChildFoo
as the `ChildBar`'s foo
property type as it is not exactly the same type as its parent's foo
, but as it doesn't have a backing field I think this should be able to compile without any problem. What am I missing there?kef
12/10/2018, 12:05 AMcurrent.prev.prev.prev.prev.prev.prev.prev
should be the fastest way possible, but out of curiosity I also did it as
generateSequence(current) { it.prev }.take(8).last()
and to my surprise, when I measured times of execution I got this :
- .prev
chain -> 2389ms
- generateSequence
-> 460ms
So why is generateSequence
5 times faster?
On my machine I get results like that when looping up to 10mln, after that generateSequence
suddenly takes 3s to finish.vngantk
12/10/2018, 2:40 AMedwardwongtl
12/10/2018, 9:51 AM???
such that toResult
won’t error? I’ve tried Nothing
and it is not working
sealed class ApiResult<T>
data class Success<T>(
val msg: String,
val data: T
) : ApiResult<T>()
data class Failure(
val error: String,
val errMsg: String
) : ApiResult<???>()
fun toResult(): ApiResult<User> {
return if (error == "0") Success(
msg = msg, data = movies
) else Failure(error = error, errMsg = errMsg)
}
mc
12/10/2018, 2:17 PMuncurry
in kotlin? That is, a function which takes a function of two arguments and returns a function which takes a single pair of arguments?locke
12/10/2018, 5:19 PMstarke
12/10/2018, 10:21 PMputAll
and put
have that same uncertaintyxenoterracide
12/10/2018, 10:34 PMif (a != null && b != null ) {
like there is with a?.let {
?xenoterracide
12/10/2018, 10:34 PMRobert Maguire
12/10/2018, 10:37 PMwck
12/10/2018, 11:20 PMwck
12/10/2018, 11:20 PMdiesieben07
12/10/2018, 11:21 PMwck
12/10/2018, 11:22 PMdiesieben07
12/10/2018, 11:24 PMclass Evil {
public static void beEvil(List<String> list) {
list.add(null);
}
}
In Kotlin:
fun main() {
val list = mutableListOf<String>()
Evil.beEvil(list)
println(list[0]) // throws an exception
}
wck
12/10/2018, 11:27 PMdiesieben07
12/10/2018, 11:28 PMwck
12/10/2018, 11:31 PMdiesieben07
12/10/2018, 11:32 PMwck
12/10/2018, 11:36 PMBernhard
12/10/2018, 11:46 PMwck
12/10/2018, 11:47 PMBernhard
12/10/2018, 11:47 PMwck
12/10/2018, 11:49 PMBernhard
12/10/2018, 11:49 PMwck
12/10/2018, 11:51 PMBernhard
12/10/2018, 11:52 PMwck
12/10/2018, 11:59 PMBernhard
12/11/2018, 12:00 AMwck
12/11/2018, 12:03 AMgildor
12/11/2018, 12:44 AM