Consider the example below where I define two generic functions in the companion object of a generic data class:
data class CommonResponse<T>(
var data: T? = null
) {
companion object {
// WITH return type
fun <T> succeed1(): CommonResponse<T> = CommonResponse()
// WITHOUT explicit return type
fun <T> succeed2() = CommonResponse<T>()
}
}
With the given context, both functions will have the same return signature. I have no doubt that they will both work correctly, but there is still a question confusing me:
- Will omitting the return type cause any issues?