From ce346de669050a362a163fd4cabbec3899f6303a Mon Sep 17 00:00:00 2001 From: Lxh6688 <1272662790@qq.com> Date: Thu, 15 Jul 2021 23:32:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=8E=82=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/github/hcsp/encapsulation/Cat.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/hcsp/encapsulation/Cat.java b/src/main/java/com/github/hcsp/encapsulation/Cat.java index 97eba15..1918258 100644 --- a/src/main/java/com/github/hcsp/encapsulation/Cat.java +++ b/src/main/java/com/github/hcsp/encapsulation/Cat.java @@ -18,7 +18,18 @@ public class Cat { * @param name 名字 * @return 创建的猫 */ - public static Cat newCat(String name, int age) {} + private Cat(String name,int age){ + this.name=name; + this.age=age; + } + + public static Cat newCat(String name, int age) { + if(name == null || age< 0.2 || name.isEmpty()){ + return INVALID_CAT; + }else{ + return new Cat(name,age); + } + } public String getName() { return name;