is it possible to have a custom property delegate ...
# announcements
p
is it possible to have a custom property delegate that can provide a nullable value to a nullable property and a non-nullable value to a non-nullable field? aka:
Copy code
class Foo {
    val one : String by someProperty()
    val two : String? by someProperty()
}
….and if so, what would be the signature of 
operator fun getValue(…)
? I guess I could do 
val two : String? by someOptionalProperty()
 to make the type signature easier, but that feels like I’m giving up, y’know?
b
it's possible (a bunch of delegates from stdlib allows this, e.g.
lazy
) just leave it as T and perform unchecked cast if necessary (like
return null as T
)
p
🤦🏾‍♂️ that makes perfect sense, thank you!
a
there’s also the option of using
provideDelegate
if you want to return different implementations for nullable vs non-nullable properties (Gradle’s kotlin-dsl does this for project properties, for example)
👍🏾 1