0
我有以下兩個測試用例:隱含值是不一樣的隱式[功能2]
TEST CASE 1:
@Test
def testImplicit1(): Unit = {
class Person(val age: Int)
val func: Person => Int = p => p.age
implicit val x = func
val y = implicitly((p: Person) => Int)
println(func.hashCode())
println(x.hashCode())
println(y.hashCode())
}
X和FUNC具有相同的散列碼,而y的哈希碼與另外兩個不同。
測試案例2:
@Test
def testImplicit2(): Unit = {
class Person(val age: Int)
implicit val p = new Person(10)
val p2 = implicitly[Person]
println(p.hashCode())
println(p2.hashCode())
}
p和P2具有相同的散列碼
我會問爲什麼Ÿ的哈希碼是在測試用例FUNC和X的不同1
你是對的..謝謝! – Tom