When importing maven dependencies for GraphQL, got a error (The type java.util.Optional cannot be resolved. It is indirectly referenced from required .class files). I have a class in my project which is extending SimpleGraphQLServlet. The SimpleGraphQLServlet implementation is using the Java.Util.Optional class but this class is not found in java 7 library. I can't upgrade my project java version to 8. Can anyone please provide me a solution to this problem.
(This question is not duplicate as intelliJ Optional class issue. This is related to Graphql library)
Streams and Optional
were added only in Java 8. You may be able to use the streamsupport library, which provides a backport into the java.util
space.
Note that using this library makes it likely that you'll have problems running on Java 8, and it's not exactly compatible, so if it's actually absolutely impossible to use Java 8, then you can try that, but keep in mind Java 9 is now out and Java 7 is obsolete.
Edit: I have not used streamsupport, and it appears that I incorrectly interpreted the documentation (it's not an exact backport), so this option may not work with a precompiled jar. In any case, moving to a modern platform is by far the best solution.