Paula Muldoon
09/04/2020, 6:08 PMThiago Nerys
09/04/2020, 8:08 PM@JvmStatic val response = @Annotation()
but it doesn't work.khalil
09/05/2020, 1:03 AMT : X
(type T that implements/extends a type X)?Slackbot
09/05/2020, 6:50 AMWesley Acheson
09/05/2020, 8:47 AMishitatsuyuki
09/05/2020, 9:24 AMBurkhard
09/05/2020, 2:14 PMkotlin.jvmTarget = "1.8"
I get an error " Could not expand ZIP .../kotlin-stdlib-jdk7-1.4.0.jar". Also with jvmTarget 1.6 it still fails with "Error while instantiating tests: unable to set 'list' on Runner. This plugin version doesn't seem to be compatible with JMH 1.25."jean
09/05/2020, 9:58 PMsealed class State {
object Initial : State()
object Loading : State()
object Loaded : State()
data class Error(val message: String) : State()
}
Now when I try to compile State::class.sealedSubclasses
I get the error Unresolved reference: sealedSubclasses
Do I need a special dependency for it?df
09/05/2020, 10:25 PMMark
09/06/2020, 3:36 AMfkrauthan
09/06/2020, 6:59 AMe: DBHealth.kt: (13, 22): Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option
Or Cohen
09/06/2020, 8:47 AMNikola Milovic
09/06/2020, 2:19 PMfun isPerfectSquare(num: Int): Boolean {
var l = 1
var r = num
while (l <= r) {
val mid: Long = (l + (r - l) / 2).toLong()
if (mid == num.toLong() / mid) { // here is where the problem is as 19/4 gives 4 instead of 4.75
return true
} else if (mid < num.toLong() / mid) {
l = mid.toInt() + 1
} else {
r = mid.toInt() - 1
}
}
return false
}
And the Java version (this one works)
public boolean isPerfectSquare(int num) {
int low = 1, high = num;
while (low <= high) {
long mid = (low + high) >>> 1;
if (mid * mid == num) {
return true;
} else if (mid * mid < num) {
low = (int) mid + 1;
} else {
high = (int) mid - 1;
}
}
return false;
}
Basically the issue is, how to keep the floating precision in this example? I've encountered this problem a couple of times now. Try the Kotlin solution with 19 as input
Thanks!Quantum64
09/06/2020, 8:01 PMPHaroZ
09/07/2020, 1:01 PMdata class ValueHolder<A> (val value: A){
@OptIn(ExperimentalContracts::class)
inline fun <reified B : A> valueIs(): Boolean {
contract {
returns(true) implies (this@ValueHolder is ValueHolder<B>) // <- compiler error here "Cannot check for instance of erased type: ValueHolder<B>"
}
return value is B
}
}
the goal is to use #valueIs
in a when statement and benefit of smart-casting in branch as
when {
valueHolder.valueIs<TypeA> -> doStuffWithAHolder(valueHolder)
valueHolder.valueIs<TypeB> -> doStuffWithBHolder(valueHolder)
}
Ale
09/07/2020, 7:58 PMprivate fun extractLevels(querySnapshot: QuerySnapshot): List<Level?> {
return querySnapshot.documents
.map { it.toObject(Level::class.java) }
}
If the list of documents is empty, this should just return an empty list, right? There shouldn't be nulls in the list. However, unless I set the return type as List<Level?>), I get an error because it's actually expecting that. What am I doing wrong, and how can I have this return a List<Level> ?CLOVIS
09/07/2020, 9:48 PMAndrew Gazelka
09/07/2020, 11:53 PMPriorityQueue
, where each value V
is sorted by according to a calculated priority: K = calc(V, otherStuff)
. I want to be able to remove and add V
to this priority queue based on equality. Should I
1. Have a Map<V,K>
that the priority queue references in the sorting function and store the raw V
in the priority queue
2. Use something like NodeEqValue<K,V>
that has overridden equality for V
3. Implemented some custom collection like TreeMap
but that allows multiple equivalent keys
4. Add custom remove (probably the best)rrva
09/08/2020, 10:24 AMfoo<T>()
inline fun <reified T> foo(): T? {
return bar<T>()
}
inline fun <reified T> bar(): T? {
return objectMapper.readValue<T>(x)
}
Something like the abovetim
09/08/2020, 3:12 PMNir
09/08/2020, 3:45 PMMap
does not inherit from Collection
?vinny2020
09/08/2020, 5:02 PMSlackbot
09/08/2020, 5:42 PMjojo.lichtenberger
09/08/2020, 6:44 PMclass XmlSessionDBCollection(
private val ctx: RoutingContext,
private val dbCollection: TemporalNodeCollection<AbstractTemporalNode<XmlDBNode>>, AutoCloseable,
private val user: User
) : TemporalNodeCollection<AbstractTemporalNode<XmlDBNode>>, AutoCloseable by dbCollection {
Steve
09/08/2020, 8:26 PMTwoClocks
09/09/2020, 1:15 AMBilel El Oud
09/09/2020, 8:01 AMCLOVIS
09/09/2020, 9:50 AM<T: out Comparable>
to get the first one, but I don't see how to have two constraints.npayyappilly
09/09/2020, 11:07 AMGSON
format conversion - Integer
becomes Double
Type ?Nir
09/09/2020, 2:09 PMimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4.0"
kotlin("kapt") version "1.4.0"
}
group = "FooBarBaz"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
maven ("<https://dl.bintray.com/arrow-kt/arrow-kt/>" )
}
val arrow_version = "0.10.5"
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("io.arrow-kt:arrow-optics:$arrow_version"))
implementation(kotlin("io.arrow-kt:arrow-syntax:$arrow_version"))
implementation(kotlin("io.arrow-kt:arrow-optics:$arrow_version"))
//kapt("io.arrow-kt:arrow-meta:$arrow_version")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
sourceSets.main {
java.srcDirs("src/main/java", "src/main/kotlin")
}
My hello world file is in src/main/kotlin/main.kt
Nir
09/09/2020, 2:09 PMimport org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4.0"
kotlin("kapt") version "1.4.0"
}
group = "FooBarBaz"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
maven ("<https://dl.bintray.com/arrow-kt/arrow-kt/>" )
}
val arrow_version = "0.10.5"
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("io.arrow-kt:arrow-optics:$arrow_version"))
implementation(kotlin("io.arrow-kt:arrow-syntax:$arrow_version"))
implementation(kotlin("io.arrow-kt:arrow-optics:$arrow_version"))
//kapt("io.arrow-kt:arrow-meta:$arrow_version")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
sourceSets.main {
java.srcDirs("src/main/java", "src/main/kotlin")
}
My hello world file is in src/main/kotlin/main.kt
ephemient
09/09/2020, 2:33 PMNir
09/09/2020, 2:39 PMephemient
09/09/2020, 2:48 PMplugins {
application
}
application {
mainClassName = "MainKt"
}
then you could run ./gradlew run
, for exampleNir
09/09/2020, 2:52 PMephemient
09/09/2020, 2:54 PMNir
09/09/2020, 2:57 PMephemient
09/09/2020, 2:58 PMNir
09/09/2020, 3:10 PMnanodeath
09/09/2020, 3:36 PMNir
09/09/2020, 4:27 PM