简体   繁体   English

如何在Eclipse中指定嵌套的泛型

[英]how to specify nested generics in eclipse

I want to specify this type: 我想指定这种类型:

Map<String,Map<String,String>> blah = null;

But Eclipse refuses this. 但是Eclipse拒绝了。 I am not sure if it is Eclipse or the Java parser. 我不确定是Eclipse还是Java解析器。

I had similar issues when trying to write my own java parser at study times: ">>" was regarded as the shift operator. 在学习时尝试编写自己的Java解析器时遇到了类似的问题:“ >>”被视为移位运算符。

What's going on here? 这里发生了什么?

Edit: java works for this. 编辑:java为此。

It could be because your eclipse is set up to use a compiler version for java 1.4 which doesn't have generics. 可能是因为您的日食设置为使用Java 1.4的编译器版本,而该版本没有泛型。

Does it work if you just do 如果你做的话能奏效吗

Map<String,String> map = null;

EDIT: Setting in eclipse 编辑:在日食中设置 在此处输入图片说明

No problem for me as expexted... 对我来说没问题...

Indeed you can for sure define nested generic like you was doing 确实,您可以像以前一样确定定义嵌套的泛型

Map<String,Map<String,String>> blah = null;

Event doing this will not cause problems 事件这样做不会导致问题

Map<String,Map<String,Map<String,String>>> blah = null;

It is not a problem of nested generic (Java support this feature), it is a problem of generic support. 这不是嵌套泛型的问题(Java支持此功能),而是泛型支持的问题。 Be sure to have the right settings for your compiler in Eclipse, you have to set at least java 1.5 for enabling generics. 确保在Eclipse中为编译器设置正确的设置,您必须至少设置java 1.5才能启用泛型。 (Windows->Preferences->Java-Compiler and then check the version). (Windows-> Preferences-> Java-Compiler,然后检查版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM