java LocalDate 在 LocalDate 中具有私有访问权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35364532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LocalDate has private access in LocalDate
提问by Tarikh Chouhan
I am trying to find out someones age. I am following the answer given in here: How do I calculate someone's age in Java?
我试图找出某人的年龄。我正在按照此处给出的答案进行操作: 如何在 Java 中计算某人的年龄?
This is what I have so far:
这是我到目前为止:
public void setDOB(String day, String month, String year){
LocalDate birthDate = new LocalDate(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
}
I am getting a an error when declaring the birthDate variable. I am getting the following error:
声明birthDate 变量时出现错误。我收到以下错误:
LocalDate(int,int,int) has private access in LocalDate
LocalDate(int,int,int) 在 LocalDate 中具有私有访问权限
. I don't know what this error means but I am assuming its to do with data access (e.g. private, public, etc)
. 我不知道这个错误是什么意思,但我假设它与数据访问(例如私有、公共等)有关
回答by wero
The constructor you are calling is private.
您正在调用的构造函数是私有的。
You need to call
你需要打电话
LocalDate birthDate = LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
to construct your date.
构建你的约会。