LeoColman
06/25/2019, 9:07 PMRobert Menke
06/25/2019, 9:08 PMRobert
06/25/2019, 10:06 PMvictoralissont5
06/25/2019, 11:10 PMaidan
06/26/2019, 8:34 AMrdgoite
06/26/2019, 3:47 PMnikolaymetchev
06/26/2019, 6:15 PMHullaballoonatic
06/27/2019, 2:21 AMinterface Foo {
val foo: Int
val bar: String?
companion object {
operator fun invoke(foo: Int, bar: String? = null) = object : Foo {
override val foo = foo
override val bar = bar ?: otherLogic...
// etc
}
}
}
In a lot of ways it's like having the ability to inherit from multiple classes. That's probably not a good freedom to have, though.
invoke
operator has a few advantages over constructor
, too, such as error checking the arguments prior to instantiating the object.
This also opens up delegation to cut down on code
You'd think it'd be unfortunate you couldn't do this:
class Foozle(foo: Int, bar: String?) : Foo(foo, bar)
But you can instead just do this:
class Foozle(foo: Int, bar: String?) : Foo by Foo(foo, bar)
I'd love to hear the drawbacks to this overall approachPaul Woitaschek
06/27/2019, 8:17 AMas
and when do you use the prefix to
?bod
06/27/2019, 8:24 AMfun foo(vararg pairs: Pair<String, (String) -> FooBar>)
When I call it like this:
foo(
"a" to { _ -> FooBar() },
"b" to { _ -> FooBar() }
)
I get warning saying that _ ->
is redundant. But, if I remove it I get
Type inference failed. Expected type mismatch: inferred type is Pair<String, () -> FooBar> but Pair<String, (String) -> FooBar> was expected
Could this be a problem with the "new type inference algorithm"?Neil
06/27/2019, 9:16 AMmike_shysh
06/27/2019, 10:52 AMClass<T> type
Is it possible to provide List<ObjectA>.class (seems such syntax is not ok in kotlin)?juliocbcotta
06/27/2019, 1:55 PMT
fun getListener(): MyListenerInterface {
return when {
parentFragment is MyListenerInterface -> parentFragment as MyListenerInterface
targetFragment is MyListenerInterface -> targetFragment as MyListenerInterface
else -> context as MyListenerInterface
}
}
jw
06/27/2019, 2:07 PMtypeOf
intrinsic to create a KType
but you cannot get a Type
from that without kotlin-reflect... yet https://youtrack.jetbrains.com/issue/KT-32241LS
06/27/2019, 3:46 PMmutableMapOf()
?
i need the map to be thread-safe, and also hold its entries in the order of insertion.Nicole
06/27/2019, 5:03 PMFloat.NaN
which led to this odd result: Float.NaN === Float.NaN
is false
with JVM and JS targets, and true
with Kotlin/Native. — I see that identity equality for Float
has been deprecated, but still figured I should check if this is a bug (and should be reported) or if it’s just “undefined behavior”Hullaballoonatic
06/27/2019, 6:42 PM&
, |
for anything? Bitwise operators? Would be kinda neat if |
could be a new bracket type if kot, but that would be weirdly different from industry standard.streetsofboston
06/27/2019, 7:32 PMlaunch
from a scope without a CoroutineExceptionHandler)?
Update: Solvedmathew murphy
06/27/2019, 10:22 PMlaunch (newSingleThreadContext("DedicatedThread")) {
Thread.sleep(1000L)
}
laimiux
06/27/2019, 10:22 PMval optional: String? = if (someCondition) { "" }
ValV
06/28/2019, 12:48 PMkotlinx.cli
in project (Gradle)? I'm not sure that I'm adding it correctly as a dependency (it is not found). Or I'm missing something else?haroldadmin
06/28/2019, 4:40 PMmathew murphy
06/28/2019, 5:21 PMwith (foo)
block, is there any way to indicate that I mean variable bar
from outside the block, rather than a property bar
of object foo
?mathew murphy
06/28/2019, 5:57 PMuse
and with
?Timothy Wong
06/28/2019, 7:08 PMvar local variables - if the variable is not modified between the check and the usage, is not captured in a lambda that modifies it, and is not a local delegated property;
Luis Munoz
06/28/2019, 7:40 PMkevinherron
06/28/2019, 7:41 PMNikolai
06/29/2019, 5:31 AMIf a call takes a single lambda, it should be passed outside of parentheses whenever possible.
and IDEA always show warning in code about this.
I wondering why it should be formatted in that way? Is it just style and readability guidelines? Or it have technical meaning behind it?Fudge
06/29/2019, 6:30 AMenum class Test{
foo
}
Then kotlin comes built in with values(), valueOf()
, but how can I add a new helper method like getValueNames()
?gianluz
06/29/2019, 3:48 PM@file:Repository("<https://repo1.maven.org/maven2>")
@file:DependsOn("org.apache.commons:commons-text:1.6")
import org.jetbrains.kotlin.script.util.DependsOn
import org.jetbrains.kotlin.script.util.Repository
import org.apache.commons.text.WordUtils
val hello = "helloWorld"
print(hello)
print(WordUtils.capitalize(hello))
then i execute the script:
kotlinc -cp /usr/local/lib/danger/kotlin-main-kts.jar -script script.main.kts
script.main.kts:7:12: error: unresolved reference: apache
import org.apache.commons.text.WordUtils
^
script.main.kts:11:7: error: unresolved reference: WordUtils
print(WordUtils.capitalize(hello))
^
basically doesn't resolve the dependencies 😕 and i don't want to link directly the jar when executing the script