If I try and do
fun Test ()
{
public class OpOver (theInt : Int) {
var value : Int = theInt;
fun inc() : OpOver
{
value = value + 1;
return this;
}
fun toString() : String
{
return Integer.toString(value)
}
}
var someVar = OpOver(10);
println(“The value is : ${someVar}”)
someVar++;
println(“The value after increment is : ${someVar}”)
}
I get a compile error on the “fun inc() : OpOver” line:
Error (xx,xx) Kotlin: Unresolved reference: OpOver
The IDE also highlights OpOver in red (tool tip says: Unresolved reference: OpOver).
If I move the class declaration above/outside the function declaration, then it compiles and runs.
Or, if I remove the inc() function and the ++ operation, it compiles and runs with the class definition inside the function.
Just wondering why I am getting this behavior.