【发布时间】:2010-10-11 18:05:39
【问题描述】:
我有一个 Servlet 过滤器,它执行以下类型转换:
HttpServletRequest httpRequest = (HttpServletRequest) req;
目前我的过滤器负责两个任务,最好将它们分成两个过滤器。如果我将逻辑拆分为两个过滤器,我需要进行两次强制转换。
这样的演员阵容对性能有何影响?为了更好的架构,是否值得接受这种性能下降?
【问题讨论】:
-
始终避免使用 tostring 或类似方式
-
如果我需要调用 HttpServletRequest 上的方法,字符串将无济于事。为什么更喜欢 toString 之类的而不是强制转换?
-
@deamon:看这篇帖子stackoverflow.com/questions/2170872/…Tom Hawtin 的回答。
标签: java performance casting