6. §±§â§à§ã§ä§à§Û POJO
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public DateTime getRegisterDate() {
return registerDate;
}
public void setRegisterDate(DateTime registerDate) {
this.registerDate = registerDate;
}
7. §±§â§à§ã§ä§à§Û POJO
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (name != null ? !name.equals(user.name) : user.name != null) return false;
if (email != null ? !email.equals(user.email) : user.email != null) return false;
return registerDate != null ? registerDate.equals(user.registerDate) : user.registerDate == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (registerDate != null ? registerDate.hashCode() : 0);
return result;
}
8. §±§â§à§ã§ä§à§Û POJO
public class User {
private String name;
private String email;
private DateTime registerDate;
public User() {
}
public User(String name, String email,
DateTime registerDate) {
this.name = name;
this.email = email;
this.registerDate = registerDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public DateTime getRegisterDate() {
return registerDate;
}
public void setRegisterDate(DateTime registerDate) {
this.registerDate = registerDate;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
if (name != null ? !name.equals(user.name) : user.name != null) return false;
if (email != null ? !email.equals(user.email) : user.email != null) return false;
return registerDate != null ? registerDate.equals(user.registerDate) : user.registerDate == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (registerDate != null ? registerDate.hashCode() : 0);
return result;
}
}
9. §±§â§à§ã§ä§à§Û case class
case class User(name: String, email: String,
registerDate: DateTime = DateTime.now)
val obj1 = User(?Some name?, ?Some email?)
val obj2 = obj1.copy()
val obj3 = obj1.copy(name = ?New name?)
10. §³§à§á§à§ã§ä§Ñ§Ó§Ý§Ö§ß§Ú§Ö §ã §à§Ò§â§Ñ§Ù§è§à§Þ
public abstract class Homo
pubic class HomoHabilis extends Homo {
}
public class HomoHeidelbergensis extends Homo {
}
public class HomoSapiens extends Homo {
}
public void evolve(Homo homo) {
if (homo instanceof HomoHabilis) {
HomoHabilis h = (HomoHabilis) homo
//die
return;
}
if (homo instanceof HomoHeidelbergensis) {
//cast
//die
return;
}
if (homo instanceof HomoSapiens) {
//cast
//evolve
return;
}
}
11. §³§à§á§à§ã§ä§Ñ§Ó§Ý§Ö§ß§Ú§Ö §ã §à§Ò§â§Ñ§Ù§è§à§Þ
abstract class Homo
class HomoHabilis extends Homo
class HomoHeidelbergensis extends Homo
class HomoSapiens extends Homo
def evolve(homo: Homo) {
homo match {
case habilis: HomoHabilis => //die
case heidelbergensis: HomoHeidelbergensis => //die
case sapiens: HomoSapiens => //love scala ^__^
}
}