Ivan Brko
09/18/2021, 12:56 PMSimas Butavičius
09/19/2021, 10:36 AMclass Demo {
class Normal {
val greeting = "I'm Normal class instance"
}
val normal = Normal()
private val privateAnonymous = object {
val greeting = "I'm anonymous class instance"
}
val anonymous = object {
val greeting = "I'm also anonymous class instance"
}
val normalGreeting = normal.greeting // I'm Normal class instance
val privateAnonymousGreeting = privateAnonymous.greeting // I'm anonymous class instance
val anonymousGreeting = anonymous.greeting // Unresolved reference: greeting
}
elect
09/19/2021, 4:42 PMGilles Barbier
09/19/2021, 9:09 PMKfunction
obtained from an expression such as obj::method
where obj is an instance from a Class.
How can I retrieve the underlying obj
from the Kfunction
???ursus
09/20/2021, 1:22 AMMap<String, String>
(keyed labels of UI elements), which is created dynamically via fetching the labels from api -- so not statically with string literals.
Does it make sense to implement a Trie
or is this somehow optimized under the hood in jvm since String
is so special?
I remember faintly about string interning, but that only applies to string literals and deals with copies, right?
It might be more memory efficient, however what about lookup? I believe there are native implementations of this inside when simply matching Strings
, no?
Also, turning unicode strings to char arrays won't work all that great?ursus
09/20/2021, 2:18 AMpublic class Char private constructor() : Comparable<Char> {
public fun toInt(): Int
...
}
First of all, what is this even, and why does it compile? a concrete class with no implementation of methods?
Secondly, does charArratOf('a', 'b', 'c')
create 3 instances of Char class?
Or, is there some magicJavier
09/20/2021, 10:14 AMSam Marz
09/20/2021, 3:21 PMPaul Griffith
09/20/2021, 6:08 PMval
? 🧵 ->ursus
09/21/2021, 12:42 AM:moshix
? or more conservative :base-moshi
? (:sqdelightx
, :retrofitx
etc)
same goes for my custom Flow
operators, since flow likes to keep it bare bonesMichael Marshall
09/21/2021, 5:33 PMdata class Foo(val a: String? = null, val b String? = null)
I could write
data class Foo(val a: String? = null, val b String? = null)
{
init {
requireNotNull(a ?: b)
}
}
But this only causes a crash at runtime. How do I achieve the same result with compile time safety?Daniele B
09/21/2021, 5:46 PMval signerPrivateKey : IntArray = intArrayOf(6,199,39,185,82,199,26,124,50,54,50,128,200,204,220,164,48,77,49,31,9,228,77,61,123,53,62,86,163,183,9,172,101,133,107,31,215,181,167,87)
how do I convert it to a ByteArray?Nathan Schwermann
09/21/2021, 6:38 PMAlejandro Rios
09/21/2021, 7:30 PMval first = listOf(1, 2, 3, 4, 5)
val second = listOf(1, 2, 3)
If I use first.minus(second)
I’ll get [4, 5]
but If I use second.minus(first)
I’ll get []
herlevsen
09/22/2021, 7:35 AMKarlo Lozovina
09/22/2021, 9:03 AMrepeat()
but that returns the result as a collection? to the effect like (0..i).map() { foo() }
?Hamza Ahmad
09/22/2021, 9:15 AMjeggy
09/22/2021, 9:28 AMkotlinc
inside a Docker Image.MarkRS
09/22/2021, 9:34 AMMinaSamir
09/22/2021, 9:55 AMsuhas
09/22/2021, 12:04 PMsuhas
09/22/2021, 1:11 PMigor.wojda
09/22/2021, 1:36 PMsealed interface WebSocketMessage {
data class Hello(data: String):WebSocketMessage
data class Bye(data: String):WebSocketMessage
}
enum class WebSocketMessageType(val type: String, val kotlinClass: KClass<out WebSocketMessage>) {
HELLO("hello", WebSocketMessage.Hello::class),
BYE("bye", WebSocketMessage.Bye::class),
}
// get message
val webSocketMessageType = enumValues<WebSocketMessageType>().firstOrNull { it == type }
...
I wonder if there is a way to model this using one entity, so adding the new messages types require change in a single place 🤔thanksforallthefish
09/22/2021, 2:27 PMfun MockMvc.get(urlTemplate: String, vararg vars: Any?, dsl: MockHttpServletRequestDsl.() -> Unit = {})
I defined my own version
fun MockMvc.get(urlTemplate: String, vararg vars: Any?, subject: Subject = WithMockUser.defaultUser, dsl: MockHttpServletRequestDsl.() -> Unit = {})
in a test, by mistake, I imported both extension function, but when doing mockMvc.get("/uri")
the first one got called. I am curious, how is the order defined in this case? I thought it could be the order of imports, but I tried both combination and the result did not change:
import org.springframework.test.web.servlet.get
import my.own.get
or
import my.own.get
import org.springframework.test.web.servlet.get
made no differenceBen Tilford
09/22/2021, 5:07 PM@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface SuperAnnotation {
String value();
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface SubAnnotation {
SuperAnnotation superAnnotation();
String subValue();
}
savrov
09/22/2021, 11:05 PMenshahar
09/23/2021, 1:42 AM<http://kotlin.io|kotlin.io>.path.createTempDirectory()
to create temporary directory on my kotlinc 1.4.31 but failed on Windows, WSL2 and Mac. In the Kotlin playground web, the code raises `SecurityException`(which is correct) but all my systems (including kotlinc and intelliJ IDEA) cannot resolve the package kotlin.io.path
. Is there anything I need to do to use the kotlin.io.path
package?Amol
09/23/2021, 10:23 AMdata class foo(
val a: T?,
val b: U?,
val c: V?,
val d: X?
)
This is sent as an arg to a function
bar(val foo: Foo)
Now in this function bar
, I want to allow only certain combinations of foo's members
e.g.
if(a!=null){
// If a is input, nothing else is allowed
if(b!=null || c!=null || d!= null) throw Exception()
}
if(b!=null){
// If b is input, nothing else is allowed
if(a!=null || c!=null || d!= null) throw Exception()
}
if(c!=null){
// If c is input, d is allowed, a and b not allowed
if(a!=null || b!=null ) throw Exception()
}
Obviously, more the args, the worse it gets. What is a cleaner way of doing this?elect
09/23/2021, 11:43 AMvar maxGCPauseMillis: Int
get() = error("invalid")
set(value) ..
does anyone have a better solution?Brian Donovan
09/23/2021, 4:07 PMBrian Donovan
09/23/2021, 4:07 PMPaul Griffith
09/23/2021, 4:08 PMBrian Donovan
09/23/2021, 4:09 PM