简体   繁体   English

Xcode:'-source 1.3'编译错误不支持泛型?

[英]Xcode: 'Generics are not supported in -source 1.3' compiler error?

just a quick question: 只是一个简单的问题:

I am a CS undergrad and have only had experience with the Eclipse, and Net Beans IDEs. 我是CS本科生,只有Eclipse和Net Beans IDE的经验。 I have recently acquired a Macbook and was wanting to recompile a recent school project in Xcode just to test it out. 我最近收购了一台Macbook,并且想要在Xcode中重新编译一个最近的学校项目,只是为了测试它。 Right after the line where I declare a new instance of an ArrayList: 在我声明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. 同一个项目在Eclipse中在同一台机器上编译。 I'm running OSX 10.5.4, with Java 1.5.0_13. 我正在使用Java 1.5.0_13运行OSX 10.5.4。

Thank you. 谢谢。

Java support in Xcode is obsolete and unmaintained; Xcode中的Java支持已过时且无需维护; it's the only bit of Xcode that still uses the "old" build system inherited from Project Builder. 它是Xcode的唯一一部分仍然使用从Project Builder继承的“旧”构建系统。 Even Apple suggests using Eclipse instead. 甚至Apple也建议使用Eclipse。 For Java, both Eclipse and NetBeans work quite well on the Mac; 对于Java,Eclipse和NetBeans在Mac上运行良好; if you want to try native Mac programming, use Objective-C and Cocoa, for which Xcode is fine. 如果你想尝试原生的Mac编程,请使用Objective-C和Cocoa,Xcode很好。

That said, the problem is that javac is targeting Java 1.3, which doesn't have generics. 也就是说,问题是javac的目标是Java 1.3,它没有泛型。 You can modify the javac reference in the Ant buildfile (build.xml) as follows: 您可以在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". 将“source”和“target”更改为“1.5”。

泛型是在Java 5中引入的,因此您不能将泛型与-source 1.3选项一起使用。

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 Tool)。

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. 如果您在第30行查找source="XX" target="YY" ,并将XX和YY更改为您的首选值,事情会变得更好,就像之前的帖子中所解释的那样。

Cheers, 干杯,

Pieter 彼得

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

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