sanf0rd
03/12/2018, 3:50 PMwhen()
with enums as much expressive as it is with a sealed class
benleggiero
03/14/2018, 3:48 PMAregev2
03/14/2018, 5:01 PMguenther
03/15/2018, 6:13 AMcaret
. Is there anything against this? (e.g. operator Int.caret(x: Int): Int = Math.....
)Slackbot
03/15/2018, 2:46 PMguenther
03/16/2018, 6:22 AMClass::function.name
literal a compile-time-constant?
This would really help in situations where a name for an annotation is actual a function-name like in JUnit-Parameterized-Tests:
object CalculatorTest {
@ParameterizedTest
// @MethodSource(value = CalculatorTest::multiplyNumberProvider.name) // HERE IT WOULD HELP
@MethodSource(value = "multiplyNumberProvider") // this sucks
fun `multiplication of two numbers (with params)`(num1: Int, num2: Int, expected: Int) {
...
}
fun multiplyNumberProvider(): Stream<Arguments> = ...
}
benleggiero
03/19/2018, 2:37 AMhttps://i.imgur.com/I7c9RMw.png▾
christopher
03/21/2018, 3:19 PMdeviant
03/23/2018, 2:36 PMcedric
03/25/2018, 10:30 AMnull
as false
is pretty intuitive. Kotlin by design avoids implicit conversions as much as possible, which is why that code is invalid but I don't think it would lead to bugs or hard to read code to silently convert a null
Boolean
to false
Fedor Bobin
03/30/2018, 7:51 AMhttpClient.get<Type>(...): Type <------ return type is handled from reified generic parameter
interface JsonSerializer {
suspend fun read(type: KClass<*>, content: IncomingContent): Any <<------ and handled type is used to instantiate object
}
If I pass List<MyObject> as a type parameter, I silently get List of garbage because reified generics does not include inner parameters and only List<*> will be passed to JsonSerializer.read(...)
I am wonder why not:
1) either: do not allow to pass classes with inner generics to reified methods
2) or: pass something different then just KClass that supports chain of genericsmekarthedev
03/30/2018, 6:53 PMbenleggiero
03/31/2018, 3:05 PMSlackbot
04/01/2018, 9:46 AMstephanc
04/16/2018, 1:06 PMbob?.department?.head?.name ?: "meh"
There is something like this:
bob.department.head.name ??: "meh"
cedric
04/16/2018, 6:48 PMnull
. I understand that’s the point of the operator, but I think it drifts away from Kotlin’s approach of staying away from implicit behaviors.poohbar
04/16/2018, 6:52 PM?.
operator actually works similarly. You do not have to repeat the question mark in the rest of the chain.
I thought the Kotlin approach was annoying at first but now it makes more sense to me than the C# approach and I have no need for a super elvis either.stephanc
04/17/2018, 7:29 AM.
@dalexanderstephanc
04/17/2018, 8:28 AM?
, at least there is scoping functions as well that limits this.poohbar
04/17/2018, 12:13 PM!!
on .min()
or .max()
calls where I know the collection is not empty. I kind of wish we had a NonEmptyList
that would return non-nullable types from such functions. Do you guys have a better way to handle this?karelpeeters
04/22/2018, 11:22 AMlist?[6]
would be cool as well.poohbar
04/26/2018, 8:31 PMsendilkumarn [JHipster]
04/30/2018, 2:04 PMweb assembly
karelpeeters
04/30/2018, 4:59 PM.int
if the standard way is too long.eddie
05/01/2018, 4:31 PMguenther
05/05/2018, 5:46 PMclass
with an extension property
using delegation. Of course only, when the delegated object (in this case the map) is accessible.
class Foo(val map: MutableMap<String, String> = mutableMapOf()) {
var bar1: String by map
}
var Foo.bar2: String by map
guenther
05/05/2018, 6:09 PMdimension val Int.px: MyDimensionedNumber get() = MyDimensionedNumber(this, "px")
dimension operator val Int.unaryRem: MyDimensionedNumber get() = MyDimensionedNumber(this, "%")
Then instead of using things like:
100.px
100.pct
This can be done:
100px
100%
Caleb Allen
05/07/2018, 10:47 PMclass ResponseHandler{
fun handle(success: Response.Success) {}
fun handle(error: Response.ErrorB) {}
fun handle(error: Response.ErrorA) {}
}
fun getResponse(): Response{
val r = Random()
return when (r.nextInt(3)) {
0 -> { Response.Success() }
1 -> { Response.ErrorA() }
2 -> { Response.ErrorB() }
else -> { throw IllegalStateException() }
}
}
And then calling
ResponseHandler().handle(getResponse())
This will not compile. The same effect can be achieved using if I implemented a method taking a Response
parameter like so:
fun handle(response: Response) = when (response) {
is Response.Success -> { handle(response) }
is Response.ErrorA -> { handle(response) }
is Response.ErrorB -> { handle(response) }
}
Is it possible for the compiler to resolve the type for me? Given that all possible types are handled, similar to when
benleggiero
05/08/2018, 4:16 AMbenleggiero
05/10/2018, 3:05 AM