我正在写一个实现HttpFunction的java google cloud函数。HttpFunction是一个接口,具有接收HttpRequest和HttpResponse的服务功能。在我的类中,我必须重写服务来调用HttpFunction。有没有办法把它从服务重命名为其他名字?我不认为这是可能的,从我所学到的,但想知道是否有办法,我可能不知道。
import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
public class MyFunction implements HttpFunction {
@Override public void service(HttpRequest request, HttpResponse response) throws IOException {
}
}
我希望服务被重命名为说inputProcess
public class MyFunction implements HttpFunction {
@Override public void inputProcess(HttpRequest request, HttpResponse response) throws IOException {
}
}
3条答案
按热度按时间ntjbwcob1#
HttpFunction
接口定义了一个名为service
的方法。如果你想实现接口,你有100%的义务实现那个方法的名称,以满足编译器的要求。对此没有解决方法-只需根据需要使用方法的名称。wribegjk2#
u7up0aaq3#
在
HttpFunction
接口中没有直接的方法来重命名service
方法。方法名称是接口协定的一部分,必须使用完全相同的签名和名称来实现。
如果需要为方法使用不同的名称,则必须使用所需的名称创建一个单独的方法,然后将逻辑从
service
方法委托给它。但是,请注意,
service
方法本身仍然必须按照接口的要求实现和调用。