GarouDan
06/10/2020, 11:31 PM!
operator in Kotlin?
For example, if I have MyClass defined as:
MyClass() {
run() {
println("finished")
}
}
I’d like to create a situation where doing something like this:
val myObject = MyClass()
myObject!
is equivalent to
myObject().run()
the methods will be more complex since this is for a special library that I’m doing, but the simple idea is like this.
How can we define this operator? I think it is possible because we have the !!
one.Dominaezzz
06/10/2020, 11:40 PMZach Klippenstein (he/him) [MOD]
06/10/2020, 11:42 PM!!
is not in that set.GarouDan
06/10/2020, 11:44 PM+
, -
and !
? Which are their names?Zach Klippenstein (he/him) [MOD]
06/10/2020, 11:47 PMGarouDan
06/10/2020, 11:50 PMgammax
06/10/2020, 11:56 PMnot()
operator but you won’t be able to achieve the syntax you want, but rather:
!myObject
GarouDan
06/11/2020, 12:41 AMZach Klippenstein (he/him) [MOD]
06/11/2020, 12:45 AMZach Klippenstein (he/him) [MOD]
06/11/2020, 12:45 AMGarouDan
06/11/2020, 12:48 AMMatteo Mirk
06/11/2020, 7:54 AMkqr
06/11/2020, 11:11 AMmyObject()
?GarouDan
06/11/2020, 11:16 AM!!
.
This will do some complex computations that will go to an external routine and return, the motivation is to mimic a grammar language that I’m porting to Kotlin and write as less as possible to execute the code.