score:13
Not sure about the value of this, but you can inline the implementation of ScalaRuntime._hashCode
:
case class Foo(s: String) {
override val hashCode: Int = scala.util.hashing.MurmurHash3.productHash(this)
}
score:0
toString
of the case class instance is solely dependent on its fields not hashCode
score:1
@Rumoku's answer seems to get at what's really going on here. When you declare case class Foo
it compiles into this: case class Foo extends AnyRef with Product with Serializable
(see scalac
's -Xprint:typer
option). In addition, an implementation of hashCode
is also generated as follows: override def hashCode: Int = scala.runtime.ScalaRunTime._hashCode(this)
. When you override hashCode
yourself however, this implementation is not generated. The key is that neither Product
nor Serializable
implement hashCode
so the implementation that you're picking up when you call super.hashCode
is the default implementation from AnyRef
/Any
/Object
.
score:4
Not sure what you mean by "cached hasCode", but ...
You've override hashCode
with custom solution that built from Object
, that is why you're getting false
. Remove this override and you'll get expected value.
Source: stackoverflow.com
Related Query
- Scala case class with cached hashCode
- scala case class hashcode with circular references
- How to update a mongo record using Rogue with MongoCaseClassField when case class contains a scala Enumeration
- Scala case class extending Product with Serializable
- Read CSV in Scala into case class instances with error handling
- Scala copy case class with generic type
- Scala wont pattern match with java.lang.String and Case Class
- Derived Scala case class with same member variables as base
- Scala spark: how to use dataset for a case class with the schema has snake_case?
- Replacing case class inheritance with extractors preserving exhaustiveness checks in Scala
- Problem with bounded type parameterised case class and default args in Scala
- How do I add a no-arg constructor to a Scala case class with a macro annotation?
- Scala case class with function parameters
- compare case class fields with sub fields of another case class in scala
- Modeling with Scala case class
- Using new with Scala final case class
- Slick 2.10-RC1, Scala 2.11.x, bypassing 22 arity limit with case class (heterogenous)
- Scala case class copy doesn't always work with `_` existential type
- Scala case class copy constructor with dynamic fields
- Scala - case class with 100 fields (StackOverflowError)
- Why did replacing my Scala case class with an extractor break my higher order function?
- Map table with more than 22 columns to Scala case class by Slick 2.1.0
- Scala case class copy with optional values
- Companion object in Scala isn't associating itself with case class
- Scala Case class matching compile error with aliased inner types?
- How to implement a trait with a generic case class that creates a dataset in Scala
- How do I write a scala extractor for a case class with default parameters?
- scala circe encoders/decoders for an abstract class with case classes
- how to create scala case class with struct types?
- Scala type inference not working with generic case class and lambda
More Query from same tag
- How to select subprojects to package at runtime (with ScopeFilter)?
- Type inference: Using generic methods with implicit type conversion
- Scala Reflection to get the types of all fields of an object
- How to convert the dataframe column type from string to (array and struct) in spark
- Play 2.2: do not understand one part of the application.conf config related to DB
- Filter List in Functional Programming Style
- Spark/Scala not work with @tailrec + withColumn
- Type mismatch for typesafe vectors implementation
- Log4j creating logs in multiple nodes. Want to create a single log in one node
- Scala script highlighting in intellij
- play framework 2.6 ws cannot resolve
- I am using dispatch for scala, how can I convert the response of the web service into sa JSON file?
- Playframework I believe is using java 7, I'm getting Unsupported major.minor version 51.0
- Would Scala eliminate the need for repetition here?
- stored procedures in scala.dbc
- Replace conditional logic with strategy pattern
- Pattern matching custom implementation of List ADT
- Apache ServiceMix 7, ScalaDSL, No component found with scheme: jetty
- What is the Java equivalent of a Scala object?
- How to best way to parse args yet make it clear and easy to understand
- Spark: Accumulators does not work properly when I use it in Range
- Disruptor – Last handler not invoked
- Evaluate a default parameter at runtime
- why is there a type parameter IO in Request as in http4s Request[IO]?
- How to send a message from an actor to a Websocket using Play! 2.4?
- Intermediate values during folding?
- Scala Slick 3.0 Creating Table and then Inserting Rows
- How do I use a @serializable scala object?
- How to filter files that sbt watches for changes?
- How to execute user-defined function that accepts and returns another?