How can I use `Result<T>` from Java code? My...
# announcements
s
How can I use
Result<T>
from Java code? My interface returns
Result<T>
. i am seeing
Object
instead of
Result<T>
😕
v
You probably need to show some code.
y
That is because
Result<T>
is an inline class that uses a backing field of
Any?
which, on the JVM, translates to
Object
. Can you possibly provide your usecase? Because the simplest way to approach this would be to consider any
Object
that you get to be a failure if it is
instanceof Throwable
and otherwise it is success.
2
s
Copy code
interface PropSource {

    fun <T> getProperty(key: String): Result<T>

    fun getAllProperties(): Result<Map<String, Any>>
}
i have this interface. I am using
Result<T>
here so that I can encapsulate failure in the return object.