I need to write a extension module with static methods for a specific class and theese methods will be called by his childrens. By example, i have the following definitions:
Classes
abstract class Animal {
}
class Bird extends Animal {
}
class Dog extends Animal {
}
Extension Module
class AnimalStaticExtensions {
static doSomethingBasedOnType(Animal selfType) {
if(selfType instanceof Bird) {
println("Fly")
} else if(selfType instanceof Dog) {
println("Bark")
}
}
}
Main code
Bird.doSomethingBasedOnType() // I need to get the Bird class here
Dog.doSomethingBasedOnType() // I need to get the Dog class here
When run the main code, the method doSomethingBasedOnType
is called but don't work because the argument selfType
for a static extension methods is unused and his value is always null
.
There is some way to get the class type from a static extension module?