我有这样的Java程序,但我的测试给了我这个消息:Java测试失败(的toString)
testEmployeeTostring:失败testEmployeeTostring预计< [ID [= 1013名=犹八早,工作=]采购]>却被:< [ID [= 1013, 名=犹八早,工作=]采购]>
我不得不使用@Override
,我认为这就是问题所在。我希望有人能弄清楚这个问题:
public class Employee {
int id;
String name;
JobType job;
public Employee(int id, String name, JobType job)
{
this.id = id;
this.name = name;
this.job = job;
}
@Override public String toString()
{
return ("["+ "id =" + id + ", name = " + name + ", job = " + job + "]");
}
}
重写equals()方法吗? – midhunhk
感谢大家的贡献。我没有密切关注间距。我不知道测试认为这是一件大事。我想到了。 –