I have an abstract Class:
public abstract class BaseBean {
public static String getTableName(){
return "base";
}
}
And I have several Classes extending BaseBean, for Example:
public class User extends BaseBean {
public static String getTableName(){
return "user";
}
}
(I think you already smell the Problem here)
Furthermore I have a generic Class:
public class GenericClass<T extends BaseBean> {
public String getName(){
return T.getTableName();
}
}
What I want to do:
public class Main {
public static void main(String [] args) {
GenericClass<User> userClass = new GenericClass<>();
String name = userClass.getName();
}
}
Obvilously I want the String name to be "user" but it is "base". I searched a lot, and I know that I cannot overwrite static methods, but I don't know how to achieve it otherwise.
Any ideas?