louiscad
06/25/2024, 10:58 PMDaniel Pitts
07/06/2024, 6:19 PMclass A
class B
fun make():A = A()
fun make():B = B()
fun main() {
val a:A = make()
val b:B = make()
}
Daniel Pitts
07/10/2024, 6:39 PMContext Parameters
available for use yet? I'm currently using Context Receivers
for some things, and found a show-stopping compiler bug with them.dave08
07/17/2024, 3:51 PMval baz = "foo.bar"
var foo: String
var bar: String
// for assigning the vars, not new vals...
(foo, bar) = baz.split('.')
Hayden Jones
08/07/2024, 11:39 AMOleg Yukhnevich
08/12/2024, 4:05 PMAlejandro Serrano.Mena
09/12/2024, 10:00 AMutenma
09/20/2024, 1:03 AMdmcg
09/26/2024, 8:06 AMCies
10/07/2024, 3:25 PMMaria Sokolova
11/07/2024, 11:46 AMAlejandro Serrano.Mena
12/20/2024, 5:31 PMAugusto Megener
12/28/2024, 1:13 PMimplement
statements,
they would serve as an alternative way to create extension members
kt
class Foo {
val bar = "hi"
}
implement Foo {
val baz get() = "$bar, kotlin!" // would work like val Foo .baz get() = "$bar, kotlin!"
}
syntax sugar for interface implementation wrappers for existing classes, when used in classes from other libraries
kt
class ExternalClass {
val foo= "hi"
}
interface MyInterface {
fun getText(): String
}
implement ExternalClass : MyInterface {
override fun getText() = foo
}
// internally creates a wrapper
@JvmInline
value class MyInterfaceExternalClass(val value: ExternalClass) : MyInterface {
override fun getText() = value.foo
}
// when ExternalClass is used in contexts that require MyInterface, internally the wrapper will be used, but in practice, you can use it as if it were actually ExternalClass
fun myFun(arg: MyInterface) {
println(arg.getText())
}
val obj = ExternalClass()
myFun(obj) // prints "hi"
and for separating classes in multiple files, but uniting everything in a single class, when used in project classes
// a.kt
class Class {
[...]
}
// b.kt
implement Class {
[...]
}
// c.kt
implement Class : MyInterface {
override fun getText() =randomValue
[...]
}
in my opinion this would be viable and useful, what do you think?Daniel Pitts
01/11/2025, 9:26 PMRoman Venediktov
02/04/2025, 10:16 AMJesse Gottlieb
02/04/2025, 8:12 PMapplyIf
, applyUnless
, alsoIf
, and alsoUnless
to the standard lib. I chose apply
and also
among the various scope functions because these functions simply return the receiver object, so the return type can still be known regardless of the predicate. As a server developer, I use applyIf
on builder objects quite frequently and my company has added it to an internal shared kotlin library. I suspect many kotlin devs use some version of this already.
An example would be:
inline fun <T> T.applyIf(predicate: Boolean, f: T.() -> Unit) = apply {
if (predicate) f()
}
val myPlanBuilder = MyPlan.newBuilder()
myObjectBuilder.applyIf(isSunnyOutside) {
addPlanLineItem(goGetIceCream)
}
Laxystem
02/18/2025, 10:41 AMsandwwraith
03/05/2025, 3:34 PMbobko
03/21/2025, 3:24 PMJaebaek Seo
04/16/2025, 8:56 PMDerek Peirce
04/27/2025, 6:02 AMCompletable.doOnEvent
, which takes a lambda `(Throwable?) -> Unit`:
myCompletable.doOnEvent { doSomething() }
However, this started throwing exceptions. As it is a Java method, Kotlin automatically regarded it
as Throwable!
and therefore Throwable
, and as soon as the lambda was called with a null value, it did a null check and threw a NPE, even though it was verifying a value that went completely unused.
As the only reason Kotlin automatically treats Throwable!
as Throwable
here is for convenience, could it recognize in this case that the parameter is entirely unused, and therefore not overeagerly perform a null check? The solution to avoid the exception is to specify { _: Throwable? -> doSomething() }
, which I'd rather not need to specify, and I'd especially have preferred not to have to deal with the exception in the first place at all.Daniele Segato
05/22/2025, 3:36 PM?
and !!
will be used as well for error types, how are we going to differentiate between null and error in a function returning a nullable type?
fun foo() String? | SomeError
I was surprised this wasn’t addressed at all in the talk.
Are we supposed to either write functions with error union types OR functions returning nullable without error union types?
What about generics versions of this?
A null
can be a valid successful responseYoussef Shoaib [MOD]
05/27/2025, 4:43 PMfun <T> add(first: T, second: T)
Nor this function:
context(t: T) fun <T> foo(list: MutableList<T>)
Alejandro Serrano.Mena
06/06/2025, 9:46 AMmikhail.zarechenskiy
06/06/2025, 10:51 AMRoman Efremov
06/10/2025, 3:30 PMFaiz Ilham
06/10/2025, 5:17 PMRuckus
06/16/2025, 3:25 PMJP Sugarbroad
06/20/2025, 3:35 PMAlejandro Serrano.Mena
07/02/2025, 10:56 AM