在Blackberry JDE 4.5.0中启用泛型 [英] Enable generics in blackberry jde 4.5.0

查看:74
本文介绍了在Blackberry JDE 4.5.0中启用泛型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Blackberry中编译我的应用程序时,它显示以下错误. -strong 1.3中不支持泛型 (使用-source 5或更高版本来启用泛型) 如何解决这个问题

When i compiled my application in blackberry it shows the following error. generics are not supported in -source 1.3 (use -source 5 or higher to enable generics) how to solve this

推荐答案

Java 1.3是野蛮的,没有人应该遭受其侮辱.幸运的是,有解决方案!

Java 1.3 is barbaric and no one should ever have to suffer its indignities. Fortunately, there is a solution!

泛型,枚举,覆盖中的更改返回签名,以及使Java可用的几乎所有东西都是在Java 1.5中引入的. (请参见 http://en.wikipedia.org/wiki/Java_version_history ).幸运的是,大多数Java 1.5都是向后兼容的,不需要更改JVM/字节码. (或者这可能是不幸的,因为它导致Java的泛型实现比C#弱得多.只需尝试使用带有泛型参数的静态方法/字段创建泛型类)

Generics, enums, changing return signature in overrides, and pretty much everything that makes java usable was introduced in java 1.5. (see http://en.wikipedia.org/wiki/Java_version_history). Fortunately, most of java 1.5 was designed to be backwards compatible and not require JVM / bytecode changes. (or maybe this was unfortunate, as it lead Java's implementation of generics to be much weaker than C#. just try creating a generic class with static methods / fields that use the generic parameter)

这篇IBM文章很好地解释了背景知识: http://www.ibm.com/developerworks/java/library/j-jtp02277.html

This IBM article does a good job of explaining the background: http://www.ibm.com/developerworks/java/library/j-jtp02277.html

但是,这种JVM相似性允许创建以下工具: http://retrotranslator.sourceforge.net/

But this JVM similarity allowed for creation of tools such as: http://retrotranslator.sourceforge.net/

这是我的Ant构建文件中调用Retrotranslator的部分:

This is the section from my Ant buildfile that calls retrotranslator:


 < java jar="${transformer.jar.exe}"
        fork="true"
        classpath="${epic-framework.dir}/tools/retrotranslator-runtime13-1.2.9.jar:${epic-framework.dir}/tools/retrotranslator-runtime-1.2.9.jar"
    args="-srcjar ${build.dir}/classes5.jar -target 1.3 -destjar ${build.dir}/classes5to3.jar"
 />

通过preverify.exe运行转换后的jar,然后将其提供给rapc.exe,您将拥有一个使用Java 1.5编写的可正常运行的Blackberry应用程序.

Run the converted jar through preverify.exe and then give it to rapc.exe and you will have a working Blackberry app written with Java 1.5.

我错过了原始帖子中的关键细节.除了是Java 1.3,Blackberry类层次结构还缺少许多通常是Java SE 1.3 JDK一部分的类.您将首先遇到的是StringBuilder-javac将("string" +"otherstr" +"blah blah")转换为StringBuilder.append("string").append("otherstr").append("blah blah") .该类在BB上不存在,所以您会休息.但是,BB具有StringBuffer,因此在两者之间编写适配器非常容易.一个陷阱是BB禁止应用程序将类添加到java.*中.这可以在构建过程中非常有效地解决:1)在类路径上使用Java 1.5 w/java.lang.StringBuilder来构建您的应用程序,2)字符串转换java.lang.Stringbuilder(以及compat垫片中的所有其他内容)都可以运行在com.mycorp.java.lang.StringBuilder中并将其构建到JAR文件中. 3)使用带有Retrotranslator和Retrotranslator的JAR文件,将更新对java.lang.StringBuilder的所有字节码引用,以便它们现在指向com.mycorp.java.lang.StringBuilder.现在,您有了可以在Blackberry上运行的与Java 1.3兼容的字节码.

I missed a key detail in my original post. In addition to being Java 1.3, the Blackberry class hierarchy is missing many classes that would normally be a part of a Java SE 1.3 JDK. The one you will hit first is StringBuilder -- javac transforms ("string" + "otherstr" + "blah blah") into StringBuilder.append("string").append("otherstr").append("blah blah"). That class doesn't exist on BB, so you break. However, BB has StringBuffer, so writing an adapter between the two is pretty easy. The one catch is that BB disallows apps from adding classes into java.*. This can be very effectively fixed in the build process: 1) build your app against Java 1.5 w/ java.lang.StringBuilder on the classpath, 2) string transform java.lang.Stringbuilder (and everything else in your compat shim) to live in com.mycorp.java.lang.StringBuilder and build it into a JAR file. 3) Use that JAR file w/ retrotranslator and retrotranslator will update all bytecode references to java.lang.StringBuilder so that they now point to com.mycorp.java.lang.StringBuilder. Now you have a java 1.3 compatible bytecode that can be run on a Blackberry.

如果有人对此材料感兴趣,请与我联系.我可以研究一下开源的Compat库.

If anyone is interested in this stuff, contact me. I could look into open sourcing the compat library I have.

这篇关于在Blackberry JDE 4.5.0中启用泛型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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