开发者

Using Scala code in eclipse ide. Internal compiler error

开发者 https://www.devze.com 2023-03-10 22:07 出处:网络
In Netbeans, I used some scala code (jar) written by someone else and included it into a java project project along with Scala-library.jar. It worked nicely without hiccups.

In Netbeans, I used some scala code (jar) written by someone else and included it into a java project project along with Scala-library.jar. It worked nicely without hiccups.

Now when I try to do the same using eclipse, I get开发者_高级运维 the following build error

Internal compiler error: java.lang.ClassCastException:
org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding cannot be cast to 
org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding at 
org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.initializeTypeVariable(BinaryTypeBinding.java:944)   DemoApp.java    /demo/  line 0  Java Problem

On Googling, I found that others have had this problem but not seen any fixes.

If any of you have seen this error and figured how to fix it, please share it here. Let me know if any other information is needed. Unfortunately, I do not have the source of the Scala code that I used, just the jar. If you need the code of DemoApp.java, I can paste it here, but that is not very useful: it just references an object in the Scala code.

Details: scala-2.8.0.r22602-b20100720020114

Thanks.


One of the problems of Scala is its lack of binary compatibility between different versions. Either use the same library version with which the original Jar was compiled, or recompile the Jar (if that's an option).


Do you have JDT Weaving enabled? Go to Preferences -> JDT Weaving to find out. If it is disabled, then you may have inexplicable errors in your IDE.


Ok. I finally found the solution!

Thanks to this SO question

The problem seems to be Scala 2.8 compiler (apparantly). This issue is not there in 2.9. One of the fixes suggested was to use Scala 2.9, but that is not always possible. So here is the right solution.

The problem lies in the List type of Scala. I found that I was returning (exposing) a List in the Scala code somewhere, which was causing the problem with Java in Eclpise.

To fix the problem, do not return List. Return Array or some Java type.

0

精彩评论

暂无评论...
验证码 换一张
取 消