通过M2E禁用Eclipse中的泛型验证 [英] Disable generics validation in Eclipse via M2E

查看:147
本文介绍了通过M2E禁用Eclipse中的泛型验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个遗留项目来自Java 1.4(古代,我知道!),它具有所有的List和ArrayList与未指定的泛型类型。我已经将这个项目最近迁移到Maven,以便更轻松的构建自动化。



现在,当我将它导入Eclipse时,我看到许多警告,如 ArrayList是一个原始类型。引用通用类型ArrayList应该被参数化。有没有办法在pom.xml中指示M2E在将此项目导入Eclipse时自动禁用这些检查?



注意:我希望项目在Java 1.6。

解决方案

Eclipse显示警告,不一定是m2e插件。



在Eclipse中,您可以配置您的项目目标编译器,如下所示:




  • 右键单击您的项目在资源管理器

  • 选择 Java编译器

  • 点击启用项目特定设置 / li>
  • 编译器合规级别更改为 1.4





应该摆脱你在Eclipse中看到的警告。



正如@Duncan Jones所指出的那样,如果要构建使用,请将您的目标编译器添加到您的项目pom文件中通过命令行g Maven,没有任何编译时警告。



更新



如果您很乐意忽略此问题,您可以添加 @SuppressWarnings(rawtypes)作为类级注释。这将给您所需的IDE独立解决方案。


I have this legacy project coming from Java 1.4 (ancient, I know!) that has all the List and ArrayList with unspecified generic types. I have migrated this project lately to Maven for easier build automation.

Now when I import it to Eclipse I see tons of warnings like ArrayList is a raw type. References to generic type ArrayList should be parameterized. Is there any way to instruct the M2E in pom.xml to have those check automatically disabled when importing this project into Eclipse?

Note: I want the project to be compiled under Java 1.6.

解决方案

Eclipse is showing the warnings, not necessarily the m2e plugin.

In Eclipse, you can configure your projects targeted compiler like so:

  • Right click your project in the Package Explorer
  • Select Java Compiler
  • Click Enable project specific settings
  • Change the Compiler compliance level to 1.4

This should rid the warnings you're seeing in Eclipse.

As @Duncan Jones has pointed out, add your targeted compiler to your projects pom file if you want to build using Maven via the command line, without any compile time warnings.

Update

Failing this, you could add @SuppressWarnings("rawtypes") as a class level annotation if you're happy to ignore the problem. This would give you the IDE independent solution you're looking for.

这篇关于通过M2E禁用Eclipse中的泛型验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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