2

I'm having a problem running someones code in Eclipse 3.6 (Helios). The code is written with OpenJDK 7. I'm running Windows 7 and I had to install Java 7 for it. I was using Java 6 before. I get 2 kinds of errors running the code:

  1. "Cannot cast from Object to int" (also: double, long, boolean)
  2. "Cannot instantiate the type HashSet<?>"

I read casts like "(int) obj" are only possible in Java 7. In Java 6 it has to be "(Integer) obj" instead. But I set the "JRE System Library" to JRE7 and I still get that error. Is it still somehow using JRE6?

The second problem is caused by "Set set; set = new HashSet<>()". The problem is gone if you replace HashSet<>() with HashSet<String>(). Is this another Java 7 change? And why is it not working with my JRE7? Is my Eclipse too old and only able to run JRE6?

Thanks in advance, Torben

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
John
  • 909
  • 4
  • 12
  • 29

1 Answers1

3

You're describing new features in the Java 7 compiler.

You need to use the Java 7 compiler, with any version of the JRE.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • 1
    Thanks! You're right. The Java compiler in Eclipse is set to 1.6 and can't be set to 1.7. I guess installing a new Eclipse should help. – John Jun 10 '13 at 19:42