Just to clarify, success is not an array. That part is just a string whose syntax does not represent the structure of the data.
This appears to be something like a sealed class or some kind of base class. Based on the syntax here, we can tell that this is probably something like
sealed class Result<T>(
val data: T?
val exception: Exception?
) {
class Success<T>(data: T): Result<T>(data, null)
class Error(exception: Exception): Result<Nothing>(null, exception)
}
Given
Success(14).toString()
, we can expect an output of
Success[data=14]
.
Given
Success("foo").toString()
, we can expect an output of
Success[data=foo]
.
Given
Error(Exception("foo"))
, we can expect an output of
Error[exception=java.lang.Exception: foo]
The
$varName
syntax is called string interpolation. it takes the variable supplied, calls the
toString
function on it, and inserts that string into the string literal that contains it.
Hope that helps
@Mehdi Haghgoo