Java 8 documentation Date-time tutorials mistake

2019-07-15 06:20发布

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.

2条回答
啃猪蹄的小仙女
2楼-- · 2019-07-15 06:24

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

查看更多
Deceive 欺骗
3楼-- · 2019-07-15 06:28

Change this line TemporalQueries query = TemporalQueries.precision(); to this TemporalQuery<TemporalUnit> query = TemporalQueries.precision();

You can check this Java 9 documentation

查看更多
登录 后发表回答