I have the following class:
public abstract class A
{
public abstract String doSomething(String X, String Y);
public static String doSomething(String X, String Y){return X + Y;}
...
}
The issue I have is that the static and abstract doSomething() methods seem to clash as duplicates. I thought this should be fine because the static method belongs to the class, not an instance of the class, so I was going to use the abstract method to enforce the method on all subclasses and the static method as a helper so that I have nicely factored code.
I know I could probably add an interface into the mix, but I don’t really understand what’s wrong with my abstract and static methods existing on the same class. What’s wrong with this?
In Java it is valid (despite being misleading and confusing) to call a static method from an object instance rather than the class name (despite warnings generated by many compilers).
So the following seemingly valid code wouldn’t know which of those methods to call:
Unfortunately, it’s just one of the few ugly corners of the Java language.