Kashif
02/12/2020, 10:59 AMMichael de Kaste
02/12/2020, 3:16 PMdata class Activity(
val startTime: LocalDate
val endTime: LocalDate
val directTime: Int
val indirectTime: Int
val travelTime: Int
val quantity: Int
)
It's unsure how this class will be used, but at least, this is the absolute truth of the class. Later on, someone says: I want to use a specific predefined version of this activity, a data class that looks like this:
data class SpecificActivity(
val executionTime: LocalDate
val duration: Int
val quantity: Int
)
but somehow backed by the original, hence; executionTime is just startTime, duration is just endTime - startTime in minutes , and quantity is still the same, the other fields are ignored. But I also want to let everyone know, in the model, that SpecificActivity IS an Activity, just not with the represented fields. such that someone can easily say: I want this SpecificActivity, but I want that other version of it (SomeOtherSpecificActivity, that might not have dates, for example.)
I know about backing fields, sealed classes and the like, but none of them really do what I want.louiscad
02/12/2020, 4:17 PMSam Garfinkel
02/12/2020, 7:09 PMextract
here?
object Container {
val contained = mutableMapOf<String, Any>()
inline fun <reified T> extract(name: String): T = contained[name] as T
}
class Foo {
val bar: String by lazy {
Container.extract("Bar")
}
}
Because lazy
is declared to return a String
, shouldn’t the inferred type T
also be String
?Dave Jensen
02/12/2020, 9:23 PMval something: Something by lazy {}
but for unit testing I need to be able to mock retrofit. I'd also prefer that the code for building the Retrofit be encapsulated in the class itself. I have a few ideas but I'd like the Kotlin idiomatic way of doing it.Viktor Qvarfordt
02/12/2020, 10:05 PMmap
and filter
. We have recently gone through the code wiht a profiler and this led us to use asSequence
so that we have myIterable.asSequence().map { .. }.map { .. }
. Why the compiler cannot make this optimization automatically? It’s quite obious that I’m not using the intermediate object.Ellen Spertus
02/12/2020, 11:49 PMAni Mehta
02/12/2020, 11:52 PMAlessandro Tagliapietra
02/13/2020, 3:41 AMNikky
02/13/2020, 11:33 AMthana
02/13/2020, 1:52 PMChills
02/13/2020, 4:15 PMunresolved reference
user
02/13/2020, 4:30 PMFleshgrinder
02/13/2020, 5:54 PMprivate const val
symbols are kept in the bytecode. I guess for reflection but what if this is not required? There should be some kind of annotation to drop these symbols after they are inlined everywhere, no? (Maybe should post this in #language-proposals but wanted to first hear if someone has another reason than reflection to keep them.)Mike Hill
02/13/2020, 6:11 PMinline fun myInlineFun(myCase: Boolean, crossinline doSomething: () -> Unit) {
if (myCase) {
doSomething()
} else {
println("Start")
doSomething()
println("End")
}
}
The argument for the doSomething
param is written out twice in the resulting bytecode. Logically, this makes perfect sense to me -- unless there were a simple way for the compiler to remove the branches (which it does actually do if the condition is trivial, by the way), then the function must be written twice. It can have dangerous implications for uses though, especially if a caller attempts to use a long functional param.
I didn't notice a kotlinc or IntelliJ warning/inspection for this. Not sure if there are any other tools which would provide one.
Anybody else run into this?LeoColman
02/13/2020, 7:42 PMSlackbot
02/13/2020, 9:27 PMken
02/13/2020, 9:33 PMGetSubclassNamehere???
with whichever subclass called the someMethod().
abstract class A<T> {
fun someMethod(item: T?) {
try {
if (item == null) {
println("GetSubclassNamehere??? received null item")
return
}
} catch (e: Exception) {
}
}
}
class B : A<String>() {
}
fun main() {
val b: A<String> = B()
b.someMethod(null)
}
ken
02/13/2020, 10:44 PMviralshah
02/14/2020, 4:29 AMnotes
array in the following json object?
val msg = json { obj( "a" to "b", "notes" to array() ) }
Also asked this in Klaxon, but don’t know if that channel is too activeTim Malseed
02/14/2020, 4:44 AMjson
or obj
are here, so it’s hard ot say what’s possible. But you may be able to do something like:
val msg = json { obj( "a" to "b", "notes" to mutableListOf() ) }
(msg.array("notes") as MutableList).add(element)
Bruno_
02/14/2020, 9:27 AM// exposed as public
@PublishedApi
internal fun timer(name: String?, daemon: Boolean) = if (name == null) Timer(daemon) else Timer(name, daemon)
docs of published contains:
When applied to a class or a member with internal visibility allows to use it from public inline functions and makes it effectively public.
the question is: since it's internal why should I care about not making breaking changes to the declaration? It's just there for the purpose of chopping up big public inline functions, no? so published internal inline fun is like a private fun in class, right?jmfayard
02/14/2020, 9:44 AMChills
02/14/2020, 10:58 AMFleshgrinder
02/14/2020, 11:47 AMsteenooo
02/14/2020, 1:16 PMwhen
on a reified generic type?
inline fun <reified F : Foo, reified B : Bar> convert(input: F) : B {
when(B) {
Bar1 -> {}
Bar2 -> {}
}
camkadev
02/14/2020, 1:48 PMaipok
02/14/2020, 1:53 PM(min..max).toList
it takes 5000 .. 50000 -> 6.516391 s to generateCyril Scetbon
02/14/2020, 3:17 PMfrogger
02/14/2020, 3:39 PM