Created
June 2, 2012 09:54
-
-
Save komamitsu/2857586 to your computer and use it in GitHub Desktop.
[Scala] hashCode impl test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.komamitsu.hashcodetest | |
/** | |
* @author komamitsu | |
*/ | |
case class Foo(id: Int) | |
case class Bar(id: Int) | |
class Hoge(foo: Foo, bar: Bar) { | |
override def hashCode : Int = foo.## + bar.## | |
} | |
object App { | |
def main(args : Array[String]) { | |
println(new Hoge(Foo(1), Bar(2)).##) | |
println(new Hoge(Foo(2), Bar(1)).##) | |
} | |
} | |
------------------------------------------------ | |
> run | |
[info] Compiling 1 Scala source to /home/komamitsu/lab/scala/hashcodetest/hashcodetest/target/scala-2.9.1/classes... | |
[info] Running com.komamitsu.hashcodetest.App | |
-594061097 | |
-594061097 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.komamitsu.hashcodetest | |
/** | |
* @author komamitsu | |
*/ | |
case class Foo(id: Int) | |
case class Bar(id: Int) | |
case class Hoge(foo: Foo, bar: Bar) | |
object App { | |
def main(args : Array[String]) { | |
println(Hoge(Foo(1), Bar(2)).##) | |
println(Hoge(Foo(2), Bar(1)).##) | |
println(Hoge(Foo(1), Bar(2)).##) | |
} | |
} | |
------------------------------------------------ | |
> run | |
[info] Compiling 1 Scala source to /home/komamitsu/lab/scala/hashcodetest/hashcodetest/target/scala-2.9.1/classes... | |
[info] Running com.komamitsu.hashcodetest.App | |
-656140924 | |
-2107822807 | |
-656140924 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment