Xcode:“-source 1.3 中不支持泛型”编译器错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/109948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode: 'Generics are not supported in -source 1.3' compiler error?
提问by 101010110101
just a quick question:
只是一个简单的问题:
I am a CS undergrad and have only had experience with the Eclipse, and Net Beans IDEs. I have recently acquired a Macbook and was wanting to recompile a recent school project in Xcode just to test it out. Right after the line where I declare a new instance of an ArrayList:
我是一名 CS 本科生,只有 Eclipse 和 Net Beans IDE 的经验。我最近买了一台 Macbook,想用 Xcode 重新编译一个最近的学校项目,只是为了测试一下。在我声明 ArrayList 的新实例的那一行之后:
dictionary = new ArrayList<String>();
I get the following error: generics are not supported in -source 1.3.
我收到以下错误:-source 1.3 中不支持泛型。
I was just wondering if anybody could offer advice as to what the problem might be. The same project compiles in Eclipse on the same machine. I'm running OSX 10.5.4, with Java 1.5.0_13.
我只是想知道是否有人可以就可能出现的问题提供建议。同一项目在同一台机器上的 Eclipse 中编译。我正在运行 OSX 10.5.4,Java 1.5.0_13。
Thank you.
谢谢你。
回答by Nicholas Riley
Java support in Xcode is obsolete and unmaintained; it's the only bit of Xcode that still uses the "old" build system inherited from Project Builder. Even Apple suggests using Eclipse instead. For Java, both Eclipse and NetBeans work quite well on the Mac; if you want to try native Mac programming, use Objective-C and Cocoa, for which Xcode is fine.
Xcode 中的 Java 支持已过时且无需维护;它是 Xcode 中唯一仍然使用从 Project Builder 继承的“旧”构建系统的部分。甚至 Apple 也建议改用 Eclipse。对于 Java,Eclipse 和 NetBeans 在 Mac 上都运行良好;如果你想尝试原生 Mac 编程,使用 Objective-C 和 Cocoa,Xcode 就可以了。
That said, the problem is that javac is targeting Java 1.3, which doesn't have generics. You can modify the javac reference in the Ant buildfile (build.xml) as follows:
也就是说,问题在于 javac 的目标是 Java 1.3,它没有泛型。您可以修改 Ant 构建文件 (build.xml) 中的 javac 引用,如下所示:
<target name="compile" depends="init" description="Compile code">
<mkdir dir="${bin}"/>
<javac deprecation="on" srcdir="${src}" destdir="${bin}"
source="1.3" target="1.2"
Change "source" and "target" to "1.5".
将“源”和“目标”更改为“1.5”。
回答by user7305
Generics are introduced in Java 5, so you can't use generics with -source 1.3 option.
Java 5 中引入了泛型,因此您不能将泛型与 -source 1.3 选项一起使用。
回答by user7305
The build.xml file is placed in
build.xml 文件放在
/Developer/Library/XCode/Project Templates/Java/Java Tool/build.xml
(replace Java Tool with your own kind of project).
(用您自己的项目类型替换 Java 工具)。
If you look for source="XX" target="YY"
in line 30, and change XX and YY to your preferred values, things go better, much as explained in the previous posts.
如果您source="XX" target="YY"
在第 30 行中查找,并将 XX 和 YY 更改为您喜欢的值,事情会变得更好,就像在之前的帖子中解释的那样。
Cheers,
干杯,
Pieter
彼得