I have a function/method that receives objects (like def fun(t : Object)
). Now if someone creates a class and calls my function using an object, is there a way of finding out which class it came from?
For example a pseudo-code
class Test {
def sum() {} // some arbitrary method
}
def fun(t : Object) {
val ob = t.asInstanceOf[Test]
ob.sum() // this will work if I know the classname (Test)
}
but if the user creates a new class and sends me the object how am I supposed to typecast it and access the objects? Is there a way to find the class type using the given object? I tried to call t.getClass()
but it is not working for me. Kindly help me out !!!