I'm writing a little functional programming piece of code. I have an interface, and a class which has a function that gets an implementation of that interface as a param.
public interface Statement
{
T executeTStatement();
}
public class StatementExecutor
{
public static<T> T executeStatement(Statement statement)
{
T result;
try
{
.
.
result = statement.executeStatement();
.
.
}
catch.....
finally....
return result;
}
}
So the StatementExecutor class and executeStatment function in class are fine, since executeStament declared with static and does not require to have in class declaration. But since static is an illegal modifier for the interface method, the same cannot be done in the interface, I only can add to interface declaration, and I want avoid it cause there will be only one generic method in that interface. So the question is, if I get to such situation there something wrong in my design, or it just limitation of java ? And is there some trick to declare generic method in interface without declaring it on interface level ?