luke
01/29/2020, 2:19 PMContinuation
in my Java code when trying to run async coroutines. Anyone have any resources?Sandy
01/30/2020, 4:33 AMSandy
01/30/2020, 4:39 AMitnoles
01/30/2020, 5:37 AMCollections.sort(contributors, (c1, c2) -> c2.contributions - c1.contributions);
aeruhxi
01/30/2020, 7:36 AMfun x(a: String) {
print(::a.name) // References to variables aren't supported yet.
}
val someVar = 1;
x(someVar) // ::a.name should be someVar
Is there a way to know the name of a property or a variable passed to the function by reflection?ivano
01/30/2020, 8:18 AMmakeCashPeriod()
I get a nice randomized model, but I need to change some of the parameters depending by the test. Can I achieve that with the language from intelliJ usign something ,do not know, maybe generics, default constructor values, other?Ben Madore
01/30/2020, 4:24 PMinline
classes https://jira.spring.io/browse/DATACMNS-1517 - what’s the appropriate place to provide this feedback to the kotlin team on the “experimental” inline classes?Rob Murdock
01/30/2020, 4:36 PMval function1: (Int, String, Byte) -> String = { i: Int, s: String, byte: Byte -> "example" }
val function2: (String) -> Int = { -1 }
//to get something like
val function3: (Int, String, Byte) -> Int = function1.then(function2)
obviously the “then” function is fictional otherwise i wouldn’t ask. I’d love to be able to do this without actually having to know function1's arguments explicitly… just that it returns a type that matches the arguments of function2bbaldino
01/30/2020, 8:00 PMinline fun <reified T : Any> T.createChildLogger(
parentLogger: Logger,
childContext: Map<String, String> = emptyMap()
): Logger =
parentLogger.createChildLogger(getClassForLogging(T::class.java).name, childContext)
Which is used to abstract out the logic for obtaining the 'name' of the logger using the caller's class, but I'm finding I can't invoke it in-place when calling a parent constructor, like so:
class Foo(parentLogger: Logger) : Parent(createChildLogger(parentLogger))
I assume this is because the receiver function can't be applied here? Is there a workaround for something like this? (either in the definition of createChildLogger
, or how it would be invoked by the child class?pablisco
01/30/2020, 10:56 PMList
using Arrays.asList(...)
coming from Java and when I compare it with a list created with listOf()
in Kotlin:
https://pl.kotl.in/cQxTchtL0
Why aren’t following the equals
contract? Anyone experienced this before? 🤔bbaldino
01/30/2020, 11:03 PMfun <T : Any> T.double(num: Int): Int = num * 2
abstract class Parent(val num: Int)
// Works
class Child(
num: Int
) : Parent(double(num)) {
private companion object
}
// Error: unresolved reference 'double'
class Child2(num: Int) : Parent(double(num))
Alessandro Tagliapietra
01/31/2020, 1:51 AM{
"name": "parameters",
"type": [
"null",
{
"type": "array",
"items": "Parameter"
}
],
"default": null
so it can have a null value but the avro generator generates a java getter like this
public java.util.List<Parameter> getParameters() {
return parameters;
}
my problem is that when calling getParameters that returns null I get
java.lang.IllegalStateException: order.getParameters() must not be null
nkiesel
01/31/2020, 3:17 AM.INSTANCE
is really not a big deal but so far they are not buying it... Anyone has a better idea?
I have a mixed Kotlin and Java codebase and a singleton in Kotlin with its methods called from Java. The singleton Manager
delegates all calls to an implementation of an interface Service
(there are multiple possible implementations of Service
, Manager
picks one at startup). Right now, the code does
object Manager { val delegate = pickImpl(); @JvmStatic fun foo() = delegate.foo(); @JvmStatic fun bar(a: Int) = delegate.bar(a); ... }
and the Java code calls Manager.foo()
. This could be simplified to object Manager : Service by pickImpl()
but then the Java code has to be changed to call Manager.INSTANCE.foo()
. Is there a way to use delegation but retain the @JVMStatic
for the Java code?Luke Rohde
01/31/2020, 6:02 PMLS
01/31/2020, 6:21 PMfun <K, V> MutableMap<Set<K>, V>.put2(vararg keys: K, value: V) = put(keys.toSet(), value)
fun main() {
val map = mutableMapOf<Set<Int>, String>()
map.put2(1, 2, 3, value = "x") // no errors
map.put2(1, 2, 3, "x") // compiler error: No value passed for parameter 'value'
}
wouldn't it make sense for the compiler to figure the last argument on its own in this scenario?regu cj
02/01/2020, 4:33 AMHullaballoonatic
02/01/2020, 6:53 PMmoltendorf
02/01/2020, 6:55 PMLawik
02/01/2020, 8:27 PMval foo : String? = null
bar(foo)
fun bar(value: Any?){
when(value){
is Int? -> println("Int?") // always prints Int? when value == null
is String? -> println("String?")
}
}
Is there any way to get the actual type of value
?mhamade
02/01/2020, 10:04 PMEllen Spertus
02/02/2020, 12:32 AMprivate val SUB_REGEXES: Map<String, Pair<Regex, String>> =
SUBSTITUTIONS.keys.associate {
it to Pair(Regex("\\b$it\\b", RegexOption.IGNORE_CASE), SUBSTITUTIONS[it])
}
It doesn’t compile because SUBSTITUTIONS[it]
is of type String?
instead of the needed `String`; however, I know it is always a String
because its key is in the map SUBSTITUTIONS
.
Here’s a rewrite with associateWith
:
private val SUB_REGEXES: Map<String, Pair<Regex, String>> =
SUBSTITUTIONS.keys.associateWith {
Pair(Regex("\\b$it\\b", RegexOption.IGNORE_CASE), SUBSTITUTIONS[it])
}
Thomas Mao
02/02/2020, 1:34 PMBarddo
02/02/2020, 3:54 PMChills
02/02/2020, 3:58 PMMatthieu Stombellini
02/02/2020, 4:30 PM// myfile.kt
enum MyEnum {
HELLO, GOODBYE, HEY, GREETINGS
}
fun myFunction() {
doSomethingWith(HELLO) // instead of MyEnum.HELLO
doSomethingElse(GOODBYE) // instead of MyEnum.GOODBYE
}
I'd normally use MyEnum.HELLO
and MyEnum.GOODBYE
but I have a use case where that causes more harm than anything else.
The current workaround I use is to simply declare MyEnum
in a separate file, but that is quite annoying.
(please redirect me to the right channel where I can ask this if there's a better place for this question!)Rodrigo Silva
02/02/2020, 8:21 PMfun<T: Any> testing( id: UUID, name: String) : T {
return T
}
If no, how do I return a T ?camdenorrb
02/03/2020, 7:25 AMJorgen
02/03/2020, 8:14 AMadoptopenjdk:11-jre-hotspot
? Are there any others more appropriate? And if a kotlin app is developed and run in java 11, are there any reasons for seting jvmTarget = 1.8 i gradle? When i generate a new kotlin java 11 project using spring boot initialiser it sets the jvmTarget = "1.8"
even though i choose java 11 in the project creator.leodeleon
02/03/2020, 12:18 PMmyanmarking
02/03/2020, 3:52 PM