Any way to improve this? ```enum class IncomeType ...
# codereview
s
Any way to improve this?
Copy code
enum class IncomeType {
    EMPLOYMENT_BASE_PAY, EMPLOYMENT_BONUS_PAY, PENSION, UNKNOWN;

    companion object {
        fun valueOf(value: String, default: IncomeType): IncomeType {
            var returnVal = default

            try {
                returnVal = IncomeType.valueOf(value)
            } catch (ex: IllegalArgumentException) {
                // do nothing
            }

            return returnVal
        }
    }
}
I know I can convert this to a simple expression
Copy code
companion object {
        fun valueOf(value: String, default: IncomeType) = try { IncomeType.valueOf(value) } catch (ex: IllegalArgumentException) { default }
    }
but I feel like there's a simpler way to do it.