V
Vidar S. Ramdal
I'm twisting my brain on this problem, which is probably really
obvious, but I'm stuck.
I have an abstract class X with a static method:
public abstract class X {
public static void method() {
...
}
}
Class X is extended by many classes, e.g. class Y:
public class Y extends X {
...
}
Now, in a separate (test) class, I have a method that takes for example
class X as parameter, and should call method() on it:
public class Tests extends TestCase {
public void testMethod(Class<? extends X> clazz) {
clazz.method(); // Compile error
}
}
Why can't I call clazz.method()?
I'm probably able to get around it using reflection, but there surely
must be a simpler way?
obvious, but I'm stuck.
I have an abstract class X with a static method:
public abstract class X {
public static void method() {
...
}
}
Class X is extended by many classes, e.g. class Y:
public class Y extends X {
...
}
Now, in a separate (test) class, I have a method that takes for example
class X as parameter, and should call method() on it:
public class Tests extends TestCase {
public void testMethod(Class<? extends X> clazz) {
clazz.method(); // Compile error
}
}
Why can't I call clazz.method()?
I'm probably able to get around it using reflection, but there surely
must be a simpler way?