Skip to content

Instantly share code, notes, and snippets.

@komamitsu
Created June 2, 2012 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komamitsu/2857586 to your computer and use it in GitHub Desktop.
Save komamitsu/2857586 to your computer and use it in GitHub Desktop.
[Scala] hashCode impl test
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
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