<Kotlin: How to define a variable whose type depen...
# stackoverflow
u
Kotlin: How to define a variable whose type depends on the input? I have a function in Kotlin which takes a particular string as input. Depending on the input, I want to create a variable of a specific type and do some computations on it. For example, fun compute(input: String): Any{ if(input=="2d"){ var point: Point2D;// Points2D - x: int, y: int //initilize and do some computations return point.findDistanceFromOrigin() }else if(input=="2d-1"){ var point: Point2DWithP1AsOrigin;// Point2DWithP1AsOrigin - x: int, y:...