LocalDate在LocalDate中具有私有访问权限

Tar*_*han 6 java

我试图找出某人的年龄.我按照这里给出的答案: 如何用Java计算某人的年龄?

这是我到目前为止:

public void setDOB(String day, String month, String year){

    LocalDate birthDate = new LocalDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
}
Run Code Online (Sandbox Code Playgroud)

我在声明birthDate变量时遇到错误.我收到以下错误:LocalDate(int,int,int)在LocalDate中具有私有访问权限.我不知道这个错误意味着什么,但我假设它与数据访问有关(例如私人,公共等)

wer*_*ero 15

您调用的构造函数是私有的.

你需要打电话

LocalDate birthDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
Run Code Online (Sandbox Code Playgroud)

建立你的约会.

  • `LocalDate.of` 也接受 `int`,所以做 `LocalDatebirthDate = LocalDate.of(year, month, dayOfMonth)` 可能感觉更方便。 (3认同)
  • 下注者请发表评论 (2认同)