mc
08/04/2017, 1:35 PMsliceArray()
behaves a bit weird when out-of-bounds range is passed? Example: arrayOf("a", "b", "c").sliceArray(0 .. 3).forEach { println(it.toUpperCase()) }
jlleitschuh
08/04/2017, 3:14 PMreggar
08/04/2017, 4:18 PMdata class Foo(
val bar = true
)
jw
08/04/2017, 5:42 PMFooKt::class.java.classLoader
probably works, assuming your file is named Foo.kt
jlleitschuh
08/04/2017, 7:42 PMchansek
08/05/2017, 1:58 PMtschuchort
08/05/2017, 6:54 PMirus
08/06/2017, 8:09 AMfun main(args: Array<String>) {
val s = ""
val i = 0
val b = false
println(s::class == String::class)
println(i::class == Int::class)
println(b::class == Boolean::class)
fun test(a: Any) = when (a::class) {
String::class -> println("String")
Int::class -> println("Int")
Boolean::class -> println("Boolean")
else -> println("Else")
}
test(s)
test(i)
test(b)
}
What you expecting here? answer in thread
dumptruckman
08/06/2017, 5:42 PMDalinar
08/07/2017, 3:50 AMfun <T>
where <T>
is one of 2 or more unrelated classes? for example: <T>
can be <String>
or Map<*,*>
but nothing elsejw
08/07/2017, 4:01 AMPaul Woitaschek
08/07/2017, 11:10 AMfirstOrNull
and find
if they both do the same thing?danielspeixoto
08/07/2017, 10:55 PMeygraber
08/07/2017, 11:50 PMclass FlipOnAccess(
private val initialValue: Boolean,
private val onlyFirstAccess: Boolean = true
) : ReadOnlyProperty<Any, Boolean> {
private val flipper = AtomicInteger(1)
private val Int.isEven get() = and(1) == 0
override fun getValue(thisRef: Any, property: KProperty<*>) =
with(flipper.getAndIncrement()) {
if (this == 1) {
initialValue
}
else if (isEven || onlyFirstAccess) {
!initialValue
}
else {
initialValue
}
}
}
herder
08/08/2017, 6:13 AMkotlinc
REPL, and pretty quickly got a crash while doing this:
>>> data class Node<T>(var prev: Node<T>?, var next: Node<T>?, val data: T)
>>> val first = Node(null, null, "foo")
>>> val next = Node(first, null, "bar")
>>> first.next = next
>>> first
exception: java.lang.StackOverflowError
at Line_2$Node.toString(Line_2.kts)
at java.lang.String.valueOf(String.java:2994)
at java.lang.StringBuilder.append(StringBuilder.java:131)
Is there some way to make the built-in toString
detect these kinds of loops, or do I need to create my own for these kinds of structures?nikolaymetchev
08/08/2017, 11:49 AMdiesieben07
08/08/2017, 3:35 PMByteArrayDataInput
from Guava, etc.Paul Woitaschek
08/08/2017, 3:53 PMevkaky
08/09/2017, 6:17 AMval matrix = Array(dim1, { IntArray(dim2) })
infini
08/09/2017, 9:30 AMorangy
08/09/2017, 12:22 PMraulraja
08/09/2017, 1:47 PMkenkyee
08/09/2017, 2:34 PMuser
08/09/2017, 2:38 PMjlleitschuh
08/09/2017, 6:16 PMpniederw
08/09/2017, 8:45 PMjw
08/10/2017, 2:56 AMraulraja
08/10/2017, 9:07 AMjlleitschuh
08/10/2017, 9:01 PM* <table>
* <tr><td>source</td><td>source2</td></tr>
* </table>
*
* | source | node1 | node2 | node3|
* | -------|-------|-------|------|
* | node1 | 0.0 | 1.2 | 1.3 |
* | node2 | 2.1 | 0.0 | 2.3 |
* | node3 | 3.1 | 3.2 | 0.0 |
skennedy
08/10/2017, 9:31 PMskennedy
08/10/2017, 9:31 PMelizarov
08/10/2017, 9:32 PMskennedy
08/10/2017, 9:37 PM