Colton Idle
07/07/2021, 1:36 AMBrian Dilley
07/07/2021, 1:54 AMfun <T, E> ApiREsult<T, E>.myExtension() { }
Stefan Oltmann
07/07/2021, 10:46 AMAyfri
07/07/2021, 2:53 PMJavaClass::new
?Bradford Canonigo
07/08/2021, 1:45 AModay
07/08/2021, 9:41 AMvar result = intArrayOf(1, 2, 3, 4)
val list = result.toMutableList()
list.add(5)
result = list.toIntArray
Matias Reparaz
07/08/2021, 8:39 PMclass SomeClass<out T>(private val type: Class<T>, val getDefaultValue: () -> T) {
constructor(type: Class<T>, default: T): this(type, {default})
}
but when I upgrade I have this error
Kotlin: Overload resolution ambiguity:
public constructor SomeClass<out T>(type: Class<TypeVariable(T)>, getDefaultValue: () -> TypeVariable(T)) defined in SomeClass
public constructor SomeClass<out T>(type: Class<TypeVariable(T)>, default: TypeVariable(T)) defined in SomeClass
can someone explain me why this doesn’t work anymore and/or how can I rewrite it?Colton Idle
07/09/2021, 3:24 AMwhen (request.path) {
"/api/one/two" ->
return "blah"
"/api/three/four?arg=myArg" ->
return "boop"
I want the second case to basically be api/three/four*
instead of hard coding the arg.
Or do I have to basically refactor this and just use endsWith or something?poohbar
07/09/2021, 9:20 PMobject
can’t do generics?
class Mapper<T : Account> : RecordMapper<Record, T> {
override fun map(record: Record?): T? {
TODO("Not yet implemented")
}
}
Even better, I really just need a function, where the input is Record
and the output is T: Account
how do I declare that?oday
07/10/2021, 9:41 PMfor (i in 0 until halfIndex) {
for (j in s.length downTo halfIndex) {
println("i: ${s[i]} j: ${s[j]}")
}
}
Ayfri
07/12/2021, 5:44 AModay
07/12/2021, 12:29 PMhead
ends up changing and pointing to new elements
https://paste.ofcode.org/3h6juagTuPwvZaDEeTkwCPoday
07/14/2021, 9:30 AMval leftOne = arrayOne.drop(0).filter { it < arrayOne.first() }.toIntArray()
oday
07/16/2021, 6:16 PMassert()
?
assert(1 == 1, { "Equal" })
shows nothing in the consoleDMITRY.
07/17/2021, 2:28 PMPāvels Garklāvs
07/18/2021, 6:12 PMMiguel
07/19/2021, 9:15 AMfun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
fun Application.module() {
install(FreeMarker) {
templateLoader = ClassTemplateLoader(this::class.java.classLoader, "templates")
outputFormat = HTMLOutputFormat.INSTANCE
}
routing {
static("/static") {
resources("files")
}
get("/") {
call.respond(FreeMarkerContent("index.ftl", mapOf("entries" to blogEntries), ""))
}
Is it safe to say there's no client? Is that even a thing?
Sorry for the long format, I'm a bit confused, if after reading this you are too, I can clarify it further.MisileLab
07/20/2021, 2:51 AMCould not find method implementation() for arguments [org.jetbrains.kotlin:kotlin-test-junit:1.5.21] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
What is this error mean and how to fix it?
My build.gradle
/*
* This file was generated by the Gradle 'init' task.
*/
repositories {
mavenCentral()
maven {
url = uri("<https://papermc.io/repo/repository/maven-public/>")
}
maven {
url = uri("<https://oss.sonatype.org/content/groups/public/>")
}
maven {
url = uri("<https://repo.maven.apache.org/maven2/>")
}
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-test-junit:1.5.21")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21")
implementation("io.github.monun:kommand-api:2.2.0")
compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT")
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
Ayfri
07/20/2021, 8:36 AMconsole.count("something")
in Kotlin JVM ?
Documentation of console.count : https://developer.mozilla.org/en-US/docs/Web/API/Console/countskwalking
07/21/2021, 9:21 AM1 class Person(val pets: MutableList<Pet> = mutableListOf())
2
3 class Pet {
4 constructor(owner: Person) {
5 owner.pets.add(this) // adds this pet to the list of its owner's pets
6 }
7 }
Can someone please use above code to make an example on printing something.
Since I'm unable to understand the flow of the code I'm also unable to find what "this" in code line no. 5 does.
Thank you 🙂Sudhir Singh Khanger
07/21/2021, 11:17 AMvar drivingStyle = when (getWeatherConditions()) {
"Sunny" -> "Speedy"
"Foggy", "Rainy" -> "Safely"
"Blizzard" -> "Don't drive!"
else -> "Undefined"
}
And
sealed class Weather
object Rainy : Weather()
object Sunny : Weather()
object Foggy : Weather()
object Blizzard : Weather()
var drivingStyle = when (getWeatherConditions()) {
Sunny -> "Speedy"
Foggy, Rainy -> "Safely"
}
1. What is the benefit of using Sealed classes in this case over const
? Is it expensive to create a Sealed class over a constant? The one benefit I see is that I don't have to add else
branch if I use all classes of the Sealed class.
2. When a derived class of a Sealed class is used in a when block then does when know all the classes which extend a sealed class?Tristan
07/21/2021, 9:29 PMfun getSomething(): Something {}
val something: ReturnType<typeof getSomething> = getSomething()
It may be useful for situation where:
fun executeSomething(cb: Something.(arg: String) -> Unit) {
val something = Something()
something.cb("the arg")
}
// here the type could be different
// val cb: Parameters<executeSomething>[0] = {
val cb: SecretUser.(arg: String) -> Unit = {
println(propertyOfSomething)
}
executeSomething(cb)
I am just playing with the language 😊MisileLab
07/22/2021, 3:14 AModay
07/23/2021, 9:33 AMfor (i in 1 until array.size)
the best equivalent to this?
for num in array[1:]
oday
07/23/2021, 5:51 PMkv
07/23/2021, 6:28 PMmutableListOf<Pair?>
that I want to check the contents of. I try something like this on Kotlin 1.5.21:
fun foo(value: List<Pair?>): Boolean {
return list.contains(value)
}
I get the following error:
Type inference failed. The value of the type parameter T should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.I can remove the error by modifying it to
return list.contains<Any?>(value)
but it feels like a weird work around. Anyone got insight as to the best way to approach this?MisileLab
07/24/2021, 3:09 AMUse of enum entry names as types is not allowed, use enum type instead
My Code
https://pastebin.com/jfgSNRJukeishi kubo
07/24/2021, 12:23 PMclass A {
generateInstance(): this:class {
return this::class()
}
}
class B: A()
val b: B = B().generateInstance()
Ayfri
07/28/2021, 3:08 PMtypealias IDK<T> = (value: T) -> T
smit01
07/29/2021, 6:00 PMsmit01
07/29/2021, 6:00 PMAlejandro Rios
07/29/2021, 6:12 PMmkrussel
07/29/2021, 8:39 PMMichael Schleichardt
07/29/2021, 9:12 PMThing<T>
The <*> projection means you neither want to read nor write something with T
, but you still can use non-generic methods like size
on List
which returns just a number.CLOVIS
07/30/2021, 7:17 PM*
and Nothing
? In both cases, a function that returns it can't be calledmkrussel
07/30/2021, 7:21 PM*
makes all in usages of the type be Nothing
and all outs act as Any?
(or the upper bounds if not the default.Alejandro Rios
07/30/2021, 7:42 PMStar projections
link explain about it