Java – Try using IntStream.range() and get “This static method can only be accessed…”

Try using IntStream.range() and get “This static method can only be accessed…”… here is a solution to the problem.

Try using IntStream.range() and get “This static method can only be accessed…”

I’m using IBM JVM 8 and Eclipse. I want an iterator in an integer range.

So I tried using IntStream.range() and got a weird error. I’ve now removed the iterator section to get a minimal example of the problem. This line results in an error:

IntStream range = IntStream.range(0,max);

The error is that this static method of interface IntStream can only be accessed as IntStream.range

But isn’t that how I access it? How can I get it to work without errors?

(Of course I could use loops instead of iterators, but iterators would be neather).

Solution

QuoteIntStream java doc and Compatibility Guide for JDK 8
Interface IntStream only appeared after Java 1.8.
Use the implementation environment “JavaSE-1.8” on the Java build path to comply and rebuild the project.

Related Problems and Solutions