public String getPet() {
public String getName() {
return name;
}
public String getType(){
return type;
}
public String getDescription() {
}
return description;
}
我想将三个吸气剂捆绑成一个,这样getPet()获取getName(),getType()和getDescription()。我输入了此内容,但是我的语法有问题,我无法弄清楚。
您不能直接在Java中使用嵌套方法。您可以在一个方法中调用任意数量的方法。
所以您可能会有这样的事情
public Pet getPet() {
getName();
getType();
getDescription();
// create a pet from these method calls and return it i suppose?
}
public String getName() {
return name;
}
public String getType(){
return type;
}
public String getDescription() {
return description;
}
不过,就像其他人所说的那样,我没有看到这样做的真实理由。