How to enter a LocalDate value into BlueJ “Create Object” dialog box

这一生的挚爱 提交于 2019-12-02 08:05:19

Include package

As discussed in the comments, the solution is to add the code that creates the LocaDate, but bluej needs the fully qualified class name with the package prefix “java.time.”:

java.time.LocalDate.of(2018, 5, 30)

Not sure why it doesn't work with just LocalDate.of(...) (even with the class correclty imported), but at least this works.


Just another detail: a date has no format. Classes like LocalDate just holds values (in this case, it has year, month and day values), but a date itself has no format at all. The same date can be represented in many different formats: May 30th 2018, 2018-05-30, 30/05/18 are different formats, but all represent the same date. A date object just holds the values, and you can choose whatever format you want to represent it.

When you print a LocalDate, it implicity calls toString(), which by default chooses yyyy-MM-dd format, which is a ISO 8601 format, but as I said, that's just one of the many possible ways to format a date (although the value always stays the same). Telling that "a date has a format" is wrong and misleading.

Try converting the LocalDate in the call, such as:

TestPaper (2018-05-30, LocalDate.parse("2018/05/30"), 30/05/2018);

There are other static methods within LocalDate you can use. See here for more examples.

From your comment above, don't forget your import:

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