我有一个练习,显然是在向我们询问基本概念。但我找不到任何信息,或者至少我不确定我应该搜索什么。所以我有一个小班,我需要评论 3 个不同的构造函数。它看起来像这样:
class Person{
private String name;
private ArrayList<String> pseudos;
private String email;
//For me this one isn't a problem, it initialize a name & a mail with the two parameters and I believe the tricky part is this Array. I'm not sure but as far as I know it's okay to initialize the Array whithout getting him through parameter... Maybe I'm wrong.
public Person(String aName, String aEmail){
name = aName;
pseudos = new ArrayList<String>();
email = aMail;
}
//It seems to be the same explanation than the first one.
public Person(){
pseudos = newArrayList<String>();
}
//Apart from the uppercase I thinks this one is good, nothing is wrong.
public Person(String aName, String aMail, ArrayList<String> manyPseudos){
name = aName;
pseudos = new ArrayList<String>();
if(pseudos != null)
{
Pseudos.addAll(manyPseudos); //The uppercase here should be the problem
}
mail = aMail;
}
}
当然,我试图通过我的课弄清楚它,但我没有找到任何东西,所以我认为这是一个基于逻辑的练习......但我缺乏这种逻辑,我真的很想至少真正理解这部分因为它是非常基础的,我将不得不对其进行很多操作。
再次感谢您的指导和时间。