pambrose
09/10/2019, 8:33 PMw_bianrytree
09/11/2019, 8:53 AMpublic static <T extends A&B> void methodA()
Where A B are different interfaces
I can call the method in Java without any type like this:
methodA()
But when I call that method in kotlin I don’t know what type I should give to it
methodA</*What Should I put it here?*/>()
Any ideas?XQDD
09/11/2019, 10:37 AMepchris
09/11/2019, 7:48 PMjava.lang.ClassNotFoundException: kotlin.coroutines.jvm.internal.SuspendLambda
I’m using gradle to build the project and have this in place implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
(using old version b/c we’re on kotlin 1.3.20 for now)
Any ideas what might be going on?Sam
09/12/2019, 7:33 AMfinite state machine
?
I found some libraries implemented this concept but need more information to implementing this .
<https://github.com/Tinder/StateMachine>
<https://github.com/open-jumpco/kfsm>
LastExceed
09/12/2019, 9:02 AMmyList.dropLast(myList.size - 1 - myList.indexOf(thatObject))
) but none that really satisfies me in terms of readability. can you guys give me some suggestions? I figured the best way would involve myList.retainAll()
somehow but i couldnt find a good way to make use of itMatej Drobnič
09/12/2019, 10:18 AMCoroutineScope
. This practically requires such functions to reside on top level, since calling member extension functions of other classes is very awkward in Kotlin. But on the other hand, I fail to see how to properly handle dependencies in top level functions.
* For example if I have Downloader
class that has CoroutineScope.startDownloading
method, I can inject every dependency of the downloader easily via constructor, but calling startDownloading()
is awkward (I need to call it via with (downloader) {startDownloading())
statement).
* On the other hand, if I just create CoroutineScope.startDownloading()
top level method, it would be easy to call, but I would have to provide dependencies with every single call to that method, which would create messy code.widar
09/12/2019, 12:49 PMAndreas Unterweger
09/12/2019, 1:06 PMfun String.resourceContent() : String = javaClass.getResource(this).readText()
if i call "/token.json".resourceContent()
in the test i get null
if i call javaClass.getResource("/token.json")
in the test it works
why does this not work in an extension function?hikamaeng
09/12/2019, 2:54 PMinfix fun <A, B, C> Pair<A, B>.to(that:C) = Triple(this.first, this.second, that)
Paul Woitaschek
09/12/2019, 5:06 PMkevinmost
09/12/2019, 7:15 PMreified
from the function header and run againzachtib
09/12/2019, 7:41 PMRoberto Messina
09/12/2019, 10:55 PMSoren Valle
09/12/2019, 11:05 PMgenericBuilder
, but I don't know all the things.
class GenericClass<T> {
var property: T? = null
fun genericBuilder(builder: T.() -> Unit) {
// how to initialize T?
property?.builder()
}
}
Roberto Messina
09/13/2019, 12:21 AMwathek
09/13/2019, 2:52 PMval parsedValue = if (propertyValue is String) propertyValue.toDouble() else propertyValue as Double
VS
val parsedValue = (propertyValue as? String)?.toDouble() ?: propertyValue as Double
Marcin Wiśniewski
09/13/2019, 3:40 PMMohammed Saied Mostafa
09/13/2019, 4:30 PMKroppeb
09/13/2019, 6:15 PMtipsy
09/13/2019, 9:53 PMif (header?.startsWith("Basic ") != true) throw Exception
.
intellij is suggesting i replace this with require(header?.startsWith("Basic ") == true)
, but if i do that, header
is no longer smart castnfrankel
09/14/2019, 6:01 AMyschimke
09/14/2019, 1:54 PMKroppeb
09/15/2019, 10:05 PMandrzej
09/16/2019, 10:45 AMUser(firstName: String, lastName: String, age: Int)
to UserEntity(name: String, age: Int)
. I found that using a scope function is very useful but I don't know which would be the best. The pros and cons are as follows:
• let
seems as natural choice since it returns lambda result but having to repeat it
for every property feels a little redundant, e.g. user.let { UserEntity(it.firstName + it.lastName, it.age)}
• run
allows to eliminate it
from the above example but run
looks awkward as a mapping function, e.g. user.run { UserEntity(firstName + lastName, age)}
• with
also seems a viable option, e.g. with(user) { UserEntity(firstName + lastName, age)}
but I'm not sure if this is intended usage of with
function, in Kotlin docs it is described as a function which lambda result should not be returned or as way to introduce a helper object (https://kotlinlang.org/docs/reference/scope-functions.html), so I'm not sureGunslingor
09/16/2019, 12:13 PMpackage org.ppp.installer
object JavaGetProperty {
@JvmStatic
fun main(args: Array<String>) {
try {
val property = args.getOrNull(0)
var propertyVal: String
if (property == "java_patch") {
//Custom Properties
val fullVersion = System.getProperty("java.version", "unknown")
propertyVal = fullVersion.split("_")[1]
} else {
//Direct Unprocessed Properties
propertyVal = if (property != null) System.getProperty(property, "unknown") else "unknown"
}
print(propertyVal.trim())
} catch (e: Exception) {
print("unknown")
}
}
}
zak.taccardi
09/16/2019, 3:03 PMprivate lateinit var dog: Dog
@Before fun setUp() {
dog = Dog()
}
there would be:
private val dog by before { Dog() } // constructs `Dog` instance once per test
David Glasser
09/16/2019, 5:14 PMmap
return Lists whose get
method is O(1)? If so, is that documented?Bruno Garcia
09/16/2019, 6:45 PMval a = Some() { b = "value" }
Or do I need multiple lines for thatscottiedog45
09/16/2019, 10:40 PM@sumOnlyOddInts
above a list of ints would filter the ints.