If you just don't need anything as your type, you can use void. This can be used for implementing functions, or actions. You could then do something like this:
interface Action<T> {
public T execute();
}
abstract class VoidAction implements Action<Void> {
public Void execute() {
executeInternal();
return null;
}
abstract void executeInternal();
}
Or you could omit the abstract class, and do the return null in every action that doesn't require a return value yourself.
You could then use those actions like this:
Given a method
private static <T> T executeAction(Action<T> action) {
return action.execute();
}
you can call it like
String result = executeAction(new Action<String>() {
@Override
public String execute() {
//code here
return "Return me!";
}
});
or, for the void action (note that you're not assigning the result to anything)
executeAction(new VoidAction() {
@Override
public void executeInternal() {
//code here
}
});