遗留代码中的泛型 [英] Generics in legacy code

查看:153
本文介绍了遗留代码中的泛型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经获得了相当多的代码,只是跳到了Java 5中。我们一直在使用Java 5版本中发布的那些组件中的泛型,但其余的代码当然是,充满原始类型。我已经设置了编译器为原始类型生成一个错误,并开始手动清除它们,但按照目前的速度,它需要很长的时间来处理它(大约有 > 2500 错误)。这是Eclipse的有用的Infer Generic Type快速修复,它总是可以摆脱错误,但通常会生成需要进一步工作的代码。



有没有更好的方式可以处理有了这个?有没有比Eclipse更好的自动化工具?任何将重构应用于所有 的方法,而不是一个接一个地执行它们?或者你只是忽略了警告?

解决方案

我会建议忽略警告。否则,您将花费大量时间更新遗留代码,而不对其功能进行任何改进。

更新:来自 Luke <一个>我认为应该得到更多的可见性:
泛型是一种在编译时捕获运行时错误的方法。除非这个遗留代码存在错误,你认为它与铸造有关,否则我会离开它独自一人(如果没有损坏,不要修复)


We've got a fairly large amount of code that just made the jump to Java 5. We've been using generics in those components targeted at being released in the Java 5 version, but the remaining code is, of course, full of raw types. I've set the compiler to generate an error for raw types and started manually clearing them, but at the present rate it'll take a very long time to go through with it (there are about 2500 errors). And that's with Eclipse's helpful Infer Generic Type quick fix, which always gets rid of the errors, but often generates code that needs further work.

Is there any better way to dealing with this? Are there any automated tools better than Eclipse? Any way to apply the refactoring to all occurences instead of doing them one-by-one? Or do you just ignore the warnings?

解决方案

I would suggest ignoring the warnings. Otherwise, you'll be putting a lot of time into updating the legacy code without making any improvements to its functionality.

Update: Great comment from Luke that I thought should get more visibility: "Generics are a way to catch run time bugs at compile time. Unless this legacy code has bugs in it that you think are related to casting I would leave it alone (if it ain't broke, don't fix it)"

这篇关于遗留代码中的泛型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆