如何解决'<>'运营商不允许低于1.6 1.7源代码级? [英] How to fix '<>' operator is not allowed for source level below 1.7 in 1.6?

查看:220
本文介绍了如何解决'<>'运营商不允许低于1.6 1.7源代码级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java 1.6的Andr​​oid项目。我有一个第三方的code,这并不编译:

I have a Java 1.6 Android project. I have a third-party code that does not compile:

import org.springframework.http.HttpEntity;
//...
HttpHeaders requestHeaders = new HttpHeaders();
//...
new HttpEntity<>(requestHeaders);

它说:'&LT;>'经营者不得低于1.7源代码级

It says: '<>' operator is not allowed for source level below 1.7

我不希望我的项目切换到1.7。我已经改变了该行

I do not want to switch my project to 1.7. I have changed that line to

new HttpEntity<Object>(requestHeaders);

和现在编译罚款。

不过是我的修正是否正确?什么是Java的1.7跟空方括号?

But is my fix correct? What does Java 1.7 do with empty brackets?

更新

这是新的对象传递给接受 HttpEntity&LT功能;&GT; 参数。我明白了类型推断的想法,但我不明白什么呢从给定的code线1.7编译器推断。

That new object is passed to function that accepts HttpEntity<?> argument. I understand the idea of type inference, but I do not understand what does 1.7 compiler infer from the given code line.

推荐答案

您修复几乎是正确的,反正没有危险。

Your fix is almost correct and anyway not dangerous.

对象是层次结构和&lt根;>表示让编译器推断类型,这样会在1.7被推断任何类型将是一个对象的专业化反正。

Object is the root of the hierarchy and <> means "let the compiler infer the type", so any type that would have been inferred in 1.7 would be a specialization of Object anyway.

在看到您的更新后:<?code>&LT;&GT; 其实就是通配符的(见这里),所以对象的罚款。

After having seen your update: <?> actually means "wildcard" (see here), so Object is fine.

这篇关于如何解决'&LT;&GT;'运营商不允许低于1.6 1.7源代码级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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