The “import java.util.function cannot be resolved” error

后端 未结 8 1513
感动是毒
感动是毒 2021-01-11 12:49

I\'m trying to run this practice script from the standard Oracle Java tutorials.

This seems to be a common error and I\'ve used SO resources to make attempts to fix

相关标签:
8条回答
  • 2021-01-11 13:20

    same problem is coming to me,I make a changes in eclipse.ini file and did -Dosgi.requiredJavaVersion=1.8 instead of -Dosgi.requiredJavaVersion=1.6 and my problem has been resolved.

    0 讨论(0)
  • 2021-01-11 13:21

    Lambda Expressions are newly added into Java 8. They are not available for JRE7. Try to upgrade your eclipse project's JRE to 8 (window -> preferences->java->compiler).

    0 讨论(0)
  • 2021-01-11 13:25

    For idea IntelliJ you need to go to Menu-> Project Structure -> Module here you will see Source tab, above this tab you can see language level. change it to more than 8.

    -yash

    0 讨论(0)
  • 2021-01-11 13:25

    I had something similar with Apache Camel: the following function was not working anymore

    String headerKey = exchange.getIn().getHeader("headerKey",String.class);
    

    because of the error-message:

    The type java.util.function.Supplier cannot be resolved. It is indirectly referenced from required .class files
    

    To solve the issue I change the casting and it worked afterwards:

    String headerKey = (String) exchange.getIn().getHeader("headerKey");
    

    maybe it helps you or somebody else.

    One other point to mention here would be the Apache Camel version itself as stated on the official page linked here.

    0 讨论(0)
  • 2021-01-11 13:32

    Per the java.util.function Javadoc,

    Since:
          1.8
    

    So upgrade to Java 8, or try to find an older version of the tutorial.

    I'm new at this. How can you tell what you are running? I'm using Eclipse

    To determine your current Java version in eclipse, go to

    Help -> About Eclipse -> Installation Details (Button in
              lower Left) -> Configuration pane
    

    Look for the line java.specification.version - on my machine that is

    java.specification.version=1.8
    

    Or the line java.runtime.version - on my machine that is

    java.runtime.version=1.8.0_11-b12
    
    0 讨论(0)
  • 2021-01-11 13:32

    i solved this problem by trying following solution

    Project > Properties > Java Build Path
    Select Libraries tab
    Select JRE System Library
    Click Edit button
    Choose an alternate JRE (jre1.8.0_20)
    Click Finish button

    0 讨论(0)
提交回复
热议问题