根据您是只想做某件事还是要做某件事然后返回某事,您可以执行以下操作:
public abstract class DoSomethingClass<T>
{
protected abstract void doSomething(T arg1, T arg2, T arg3);
}
public abstract class ReturnSomethingClass<T, V>
{
public T value;
protected abstract void returnSomething(V arg1, V arg2, V arg3);
}
public class DoSomethingInt extends DoSomethingClass<Integer>
{
public DoSomethingInt(int arg1, int arg2, int arg3)
{
doSomething(arg1, arg2, arg3);
}
@Override
protected void doSomething(Integer arg1, Integer arg2, Integer arg3)
{
// ...
}
}
public class ReturnSomethingString extends ReturnSomethingClass<String, Integer>
{
public ReturnSomethingString(int arg1, int arg2, int arg3)
{
returnSomething(arg1, arg2, arg3);
}
@Override
protected void returnSomething(Integer arg1, Integer arg2, Integer arg3)
{
String retValue;
// ...
value = retValue;
}
}
public class MainClass
{
static void main(String[] args)
{
int a = 3, b = 4, c = 5;
Object dummy = new DoSomethingInt(a,b,c); // doSomething was called, dummy is still around though
String myReturn = (new ReturnSomethingString(a,b,c)).value; // returnSomething was called and immediately destroyed
}
}