Re: static methods in interfaces
"ballpointpenthief" <ballpointpenthief@yahoo.co.uk> writes:
Hopefully this is a SSCCE:
(I have reason not to use an abstract class.)
public interface TheInterface {
public static String getSomethingReleventToClass();
}
public Class AClass implements TheInterface {
private String somethingReleventToClass = "This will be different
in each class";
public static String getSomethingReleventToClass() {
return somethingReleventToClass;
}
}
public Class Application {
private TheInterface someClass;
public Application() {
someClass.getSomethingReleventToClass();
}
}
The point that Patricia et al were trying to make is that "someClass"
must be a reference to an instance of a class that implements
"TheInterface".
Therefore, making "getSomethingReleventToClass" (sic) non-static will
work just fine.
You seem to be unclear on just what "someClass" is. Perhaps you need
to put some thought/explanation into how "someClass" will be set, as
then you will (probably) realise the flaw in your reasoning?
This is why people expect/require an example that *compiles* (or in
your case, would compile if you could have static interface methods).
m.