Created
February 17, 2019 14:29
-
-
Save gantonious/1eccf112ab9ea2eefd641e8a8e8fd5a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun plus(lhs: Any, rhs: Any): Any { | |
return when (lhs) { | |
is Short -> { | |
when (rhs) { | |
is Byte -> lhs + rhs | |
is Short -> lhs + rhs | |
is Int -> lhs + rhs | |
is Long -> lhs + rhs | |
is Float -> lhs + rhs | |
is Double -> lhs + rhs | |
else -> throw IncompatibleTypesException() | |
} | |
} | |
is Byte -> { | |
when (rhs) { | |
is Byte -> lhs + rhs | |
is Short -> lhs + rhs | |
is Int -> lhs + rhs | |
is Long -> lhs + rhs | |
is Float -> lhs + rhs | |
is Double -> lhs + rhs | |
else -> throw IncompatibleTypesException() | |
} | |
} | |
is Int -> { | |
when (rhs) { | |
is Byte -> lhs + rhs | |
is Short -> lhs + rhs | |
is Int -> lhs + rhs | |
is Long -> lhs + rhs | |
is Float -> lhs + rhs | |
is Double -> lhs + rhs | |
else -> throw IncompatibleTypesException() | |
} | |
} | |
is Long -> { | |
when (rhs) { | |
is Byte -> lhs + rhs | |
is Short -> lhs + rhs | |
is Int -> lhs + rhs | |
is Long -> lhs + rhs | |
is Float -> lhs + rhs | |
is Double -> lhs + rhs | |
else -> throw IncompatibleTypesException() | |
} | |
} | |
is Float -> { | |
when (rhs) { | |
is Byte -> lhs + rhs | |
is Short -> lhs + rhs | |
is Int -> lhs + rhs | |
is Long -> lhs + rhs | |
is Float -> lhs + rhs | |
is Double -> lhs + rhs | |
else -> throw IncompatibleTypesException() | |
} | |
} | |
is Double -> { | |
when (rhs) { | |
is Byte -> lhs + rhs | |
is Short -> lhs + rhs | |
is Int -> lhs + rhs | |
is Long -> lhs + rhs | |
is Float -> lhs + rhs | |
is Double -> lhs + rhs | |
else -> throw IncompatibleTypesException() | |
} | |
} | |
is String -> lhs + rhs.toString() | |
else -> throw IncompatibleTypesException() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment