PHondogo
05/08/2020, 10:56 AMvoid test(Consumer<Test> consumer)
When I call it from kotlin
test{ it.doSmth() }
What should I do to be abble to call it from java like this
test{ this.doSmth() }
so it must behave as extension function lambdaSubhi Pandey
05/08/2020, 5:42 PME.Kisaragi
05/08/2020, 9:07 PMsupra
05/09/2020, 2:52 AMval list = listOf("A", "B", "C")
var str = "";
list.forEachIndexed() {index , element ->
str += " [$index:$element]"
}
Hullaballoonatic
05/09/2020, 3:47 PMKroppeb
05/09/2020, 5:23 PM(Entity)->Boolean
to just a Function1<Entity, Boolean>
and not to something that doesn't require boxing like `Predicate<Entity`>?ahmad
05/09/2020, 10:27 PMannotation class Decimal(val value: Int)
I mean the value
type could be for example, Int
, BigInteger
, or BigDecimal
What do you think the best approach to do this?elect
05/10/2020, 8:19 AMInt
as a Short
in the upper part of a Long
, but I get an out of range on declaring an hexadecimal number
val l = (value.toLong() shl 48) and 0xffff_0000_0000_0000 // Error:(103, 42) Kotlin: The value is out of range. Expected: Long. Found: Int
How can I solve? Casting to Long
doesnt helpelect
05/10/2020, 8:27 AMu
help maybe? (this works though (0xffff shl 48)
)Marc Knaup
05/10/2020, 4:48 PMfoo.value
resolve to Any?
and not the upper bound Bar
?LS
05/11/2020, 12:15 AMbod
05/11/2020, 8:49 AMfun parseDate(dateStr: String?): Date?
and want to express that if dateStr
is null
then the result will be null
- and also the opposite. Possible?pavankumar
05/11/2020, 9:22 AMfun main() = runBlocking {
with(CoroutineScope(coroutineContext + CoroutineExceptionHandler { _, _ -> println("Exception")})) {
val firstChild = launch() { // if i add "CoroutineExceptionHandler here, then launch coroutine will handle exception without printing on console
println("First child is failing")
delay(1000)
throw AssertionError("First child is cancelled")
}
// launch the second child
val secondChild = launch {
println("First child is cancelled: ${firstChild.isCancelled}, but second one is still active")
try {
delay(Long.MAX_VALUE)
} finally {
println("Second child is cancelled")
}
}
secondChild.join()
}
}
Jaro
05/11/2020, 10:02 AMopen class A(val strings: List<String>)
class B(strings: List<String>) : A(strings)
class C(strings: List<String>) : A(strings)
these classes are used in my REST API and I would like to validate their content with JSR annotations. I want to check that the collection strings
in class B
is not empty using @NotEmpty
but I can apply this validation only on the property declaration (if I’m not mistaken). What is the best Kotlin way to add this validation to class B
? In java I would probably override getter in class B and add annotation there, can I do something similar in Kotlin?iex
05/11/2020, 1:26 PMinline fun <reified T> listWith(count: Int, element: T): List<T> =
Array(count) { element }.toList()
FranSoto
05/11/2020, 1:26 PMLastExceed
05/11/2020, 1:40 PMLeoColman
05/11/2020, 3:38 PMAlways explicitly specify function return types and property types (to avoid accidentally changing the return type when the implementation changes)It's kind of ambiguous for me if it applies to
Unit
as well.
As I understand, it's meant for
fun test(someVar:String) = when(someVar){
"a" -> 10
else -> 20
}
where you can easily break the Int return.
Would we always specify that a certain method returns Unit, even if it's redundant?Will Harrison
05/11/2020, 5:37 PMHexa
05/12/2020, 7:12 AMRobert Jaros
05/12/2020, 11:18 AM1.4-M1
and I'm getting this warning from gradle:
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
/opt/rjaros/.gradle/wrapper/dists/gradle-6.3-all/b4awcolw9l59x95tu1obfh9i8/gradle-6.3/lib/kotlin-stdlib-1.3.70.jar (version 1.3)
...
/opt/rjaros/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4-M1/1bd127486717887634cc406a5651bd6090f11678/kotlin-stdlib-1.4-M1.jar (version 1.4)
w: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
Should I ignore this or somehow fix this?Gopal S Akshintala
05/12/2020, 1:32 PMRuckus
05/12/2020, 3:25 PMAntoine Gagnon
05/12/2020, 4:18 PMOrhan Tozan
05/12/2020, 5:16 PMspierce7
05/12/2020, 6:12 PMobject
? That seems to be a misnomer to me, and that it should be class
instead. What am I missing?Leon johnson
05/13/2020, 3:32 AMpajatopmr
05/13/2020, 12:00 PMKevin
05/13/2020, 5:25 PMBrian Dilley
05/13/2020, 7:15 PM