Consider the following example
data class DeviceResponse<T>(val status: ConnectionStatus,val data:T?,val errorMessage:String?)
ConnectionStatus can be SUCCESS, UNKNOWN_FAILURE, ATTACHMENT_NOT_MOUNTED,…etc
in case of success the data is non-null and errorMessage is null
in case of failure errorMessage is non-null and data is null
[values - data, errorMessage are depending on the connectionStatus value]
is there any way I can tell this to the compiler and compiler can do a smartcast and also impose a restriction.
or any better approach of doing this?
Thanks in advance.