36. class
User(val
id:
Int,
val
firstName:
String,
val
lastName:
String)
{
override
def
equals(obj:
Any):
Boolean
=
obj
match
{
case
that:
User
=>
id
==
that.id
case
_
=>
false
}
override
def
hashCode
=
31
*
id.##
//
識別子は更新できない
def
copy(firstName:
String
=
this.firstName,
lastName:
String
=
this.lastName)
=
new
User(firstName,
lastName)
}
object
User
{
def
apply(…):
User
=
…
}
37. //
見つけられる
val
l
=
List(
User(1,
"Yutaka",
"Hogeshiro"),
User(2,
"Junchi",
"Kato"))
l.exists(_
==
User(1,
"Yutaka",
"Yamashiro"))
//
true
38. case
class
HunterId(value:
UUID)
extends
Identity[UUID]
!
class
Hunter(
val
identity:
HunterId,
val
name:
String,
val
rank:
Int,
//
...
)
extends
Entity[HunterId]
{
//
...
}