【发布时间】:2023-03-31 11:04:01
【问题描述】:
因此,与我合作的小组减少了我们必须为某些事情输入的代码量。在这种情况下,使用 DisplayTag 库显示列表的 Spring 网页。它的完成方式是使用泛型扩展Controller 对象的类,然后为它应该处理的每个页面创建一个子类。
此控制器显示SystemErrorReport,并将类型定义为SystemErrorReportCommand。
public class SystemErrorReportController extends
GenericSearchAndSelectController<SystemErrorReportCommand> {
问题在于 SystemErrorReportCommand 作为类型传递,需要在其构造函数中手动声明自身,如下所示:
public SystemErrorReportCommand()
{
super(SystemErrorReport.class);
}
命令对象稍后被传递给需要知道其显式类型的东西。如果没有在某处手动指定它,它会以GenericCommand 的形式返回,这是我们的另一个类,因为在编译时间后SystemErrorReportCommand 位会丢失。
我对此并不感到兴奋,因为我们似乎可以进一步自动化以减少开发人员错误。有没有更优雅的方法来做到这一点,还是因为类型擦除而我坚持这样做?
【问题讨论】:
标签: java generics type-erasure