首页 \ 问答 \ 为什么要将接口声明为抽象?(Why declare an interface as abstract?)

为什么要将接口声明为抽象?(Why declare an interface as abstract?)

什么是将接口声明为抽象? 接口方法相同的东西 有一点吗?

例如。

public abstract interface Presenter {
 public abstract void go(final HasWidgets container);
}

What's point of declaring an interface as abstract? Same thing for an interface method. Is there a point to it?

eg.

public abstract interface Presenter {
 public abstract void go(final HasWidgets container);
}

原文:https://stackoverflow.com/questions/2134200
更新时间:2021-10-15 15:10

最满意答案

destroy()是卸载特定Servlet实例时由Servlet容器调用的生命周期方法。 同样,当有客户请求Servlet时, 容器将调用service()

我们可以从Servlet中的destroy()方法调用service()方法吗?

简短的回答: 是的 ,因为service()是一种像其他任何方法一样的方法。

长答案:你可以,但这没有意义。 service()需要一个请求和一个响应参数,这些参数通常在调用Servlet时由容器提供。 如果你自己打电话给service() ,你将如何提供这些参数? 做什么的? 你会在两者上使用null吗? 两个空参数的service()什么好处?

我们可以在Servlet中的service()方法中调用destroy()方法吗?

是的 ,您可以再次从service()调用destroy() ,因为它也是其他方法。 虽然仍然很奇怪,但有时这可能是有意义的,因为destroy()会执行你定义的任何逻辑(清理,删除属性等)。


重要提示:请记住,简单地调用destroy()将不会卸载 Servlet实例。 您不管理程序中Servlet的生命周期,Servlet容器就是这样。


destroy() is a lifecycle method called by the Servlet container when unloading a specific instance of the Servlet. Similarly, the container will call service() when there's a client requesting the Servlet.

Can we call service() method from destroy() method in Servlet?

Short answer: Yes, as service() is a method like any other.

Long answer: You can, but it doesn't make sense. service() requires a request and a response parameters that are usually provided by the container when the Servlet is called. If you are calling service() by yourself, how are you gonna provide those parameters? What for? Are you gonna use null on both? What good is service() for two empty parameters?

Can we call destroy() method from service() method in Servlet?

Yes, again, you can call destroy() from within the service() as it is also a method like any other. Although still strange, this could make sense sometimes, as destroy() will do whatever logic you have defined (cleanup, remove attributes, etc.).


IMPORTANT: Just bear in mind that simply calling destroy() won't unload the Servlet instance. You do not manage the lifecycle of Servlets in the program, the Servlet Container does.

相关问答

更多
  • destroy()是卸载特定Servlet实例时由Servlet容器调用的生命周期方法。 同样,当有客户请求Servlet时, 容器将调用service() 。 我们可以从Servlet中的destroy()方法调用service()方法吗? 简短的回答: 是的 ,因为service()是一种像其他任何方法一样的方法。 长答案:你可以,但这没有意义。 service()需要一个请求和一个响应参数,这些参数通常在调用Servlet时由容器提供。 如果你自己打电话给service() ,你将如何提供这些参数? ...
  • 根据服务器错误的建议,404的原因是您的路线。 代替 get "bands/favorite/:id" => "bands#destroy" 尝试: delete "bands/favorite/:id" => "bands#destroy" As suggested by the server error, the cause of your 404 is your route. Instead of get "bands/favorite/:id" => "bands#destroy" Try: del ...
  • 您的web.xml和
    都非常好。 servlet必须映射到/servleturl ,表单操作必须指向servleturl 。 错误消息还证明servlet是完美的: message HTTP method POST is not supported by this URL 否则,您将获得404 Page Not Found ( 404 Page Not Found servlet)或者更糟糕的是500 Internal Server Error (servlet无法执行)。 你得到的错误基本上意味 ...
  • 从Servlet类创建一个对象并调用该方法: public class Output extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Predicts p = new Predicts(); p.predict(); } } Cre ...
  • 编辑 : 你正在调用array.push而不是array.pushObject - 后者是一个绑定感知的Ember.js方法,这意味着它会自动更新绑定。 把手模板助手{{#each filters}}是对控制器的filters数组的绑定,模板需要知道在更新基础数组时更新。 push不告诉绑定更新,但pushObject确实如此。 这是一个有效的例子(我所做的就是将push推送到pushObject): http ://jsbin.com/asemul/6/ 这是一个非常常见的错误 - 通常,我发现如果我的模 ...
  • 从**service method ()**只有你的实际方法(获取,发布...等)决定调用。 HTTP servlet中的默认service()方法将请求路由到基于HTTP传输方法(POST和GET)的另一个方法。 例如,HTTP POST请求被路由到doPost()方法,HTTP GET请求被路由到doGet()方法。 此路由使servlet能够根据传输方法执行不同的请求数据处理。 因为路由发生在service()中,所以您不需要覆盖HTTP Servlet中的service()。 相反,根据预期的请求类 ...
  • 你为什么要重写服务方法。 没有必要这样做。 删除它或打电话 super.service(request,response); 原因 试着看看HttpServlet类的来源。 在那里你会看到,根据用于调用servlet的方法,即GET / POST,调用必要的方法doGet()或doPost()。 当容器实际收到请求时,它会启动一个新线程并通过调用service()方法为客户端提供服务。 因此,如果你覆盖它并且不调用超类的服务方法或定义你自己的策略,那么将调用GET,永远不会调用doGet()方法。 您的请 ...
  • 如果响应对象由servlet容器提供,它可以控制如何处理缓冲等事情。 例如,假设您创建了自己的ServletResponse - 如果超过一定长度,容器如何管理响应流的能力,而不是缓冲数据? If the response object is provided by the servlet container, it can control how things like buffering are handled. For example, suppose you created your own Ser ...
  • 这当然完全取决于您的实施。 如果你没有覆盖它,那么它什么都没做,因为在HttpServlet中destroy的实现是空的。 结果应用程序继续正常运行。 关于破坏方法的目的可能存在一些混淆。 目的不是servlet容器提供了一些破坏servlet的方法 。 相反,它使您可以提供一些代码,这些代码将在容器调用destroy方法时执行。 在某些情况下,当容器决定删除servlet时,需要清理资源(例如关闭数据库连接)。 容器可以独立地删除servlet:例如,如果内存不足。 方法destroy将被称为删除的一部分 ...
  • 这意味着它将清除存储在与过滤器相关的内存中的所有数据,例如要允许的URL列表,要阻止的URL列表,某些处理必须应用的URL列表等。有时它需要让用户安全上下文采取行动(即是否阻止或允许)所有这些事情将在过滤器销毁期间释放。 It means it will clean all the data stored n memory related to the filters, for example the list of urls to allow, the list of urls to block, the ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)