问题
The Oracle Tutorial page for the Temporal Query show this example code.
- Code
TemporalQueries query = TemporalQueries.precision();
System.out.printf("LocalDate precision is %s%n",LocalDate.now().query(query));
When I compile this segment code, the Compiler throws the error:
- Error
TemporalQueryExample.java:8: error: incompatible types: TemporalQuery<TemporalUnit> cannot be converted to TemporalQueries
TemporalQueries query = TemporalQueries.precision();
^
TemporalQueryExample.java:10: error: no suitable method found for query(TemporalQueries)
LocalDate.now().query(query));
^
I don't know this java 8 documentation tutorial example is correct or not but I copy this code segment and paste my IDE then IDE throw the Error.
回答1:
There is an error in the code. Look at what Lokesh has mentioned.
To further learn coding, make sure you understand the error properly. It will make your life easier. In this example, the error says: TemporalQuery<TemporalUnit>
cannot be converted to TemporalQueries
If you check your code, <TemporalUnit>
is not there, which is an indication that you have to place it somewhere and the right place to have it is mentioned by Lokesh.
You can go through this tutorial
回答2:
Change this line TemporalQueries query = TemporalQueries.precision();
to this TemporalQuery<TemporalUnit> query = TemporalQueries.precision();
You can check this Java 9 documentation
来源:https://stackoverflow.com/questions/46903033/java-8-documentation-date-time-tutorials-mistake