Java 8 documentation Date-time tutorials mistake

╄→尐↘猪︶ㄣ 提交于 2019-12-11 03:52:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!