score:3
Accepted answer
Overloading is not what the compiler is concerned about.
<console>:8: error: method parser: (identifier: String, default: String) String does not take type parameters.
This code:
parser[String](identifier, default, identity)
calls this method:
def parser(identifier: String, default: String): String
instead of this one as you would want:
def parser[T](identifier: String, default: T, modifier: String => T): T
This illustration compiles just fine:
val args = Array[String]()
def parser[T](identifier: String, default: T, modifier: String => T): T = {
val l = args.filter(_.startsWith(identifier))
if(l.isEmpty) default
else modifier(l(0).drop(identifier.length).trim)
}
def parser(identifier: String, default: String): String = "dummy"
Source: stackoverflow.com
Related Query
- Overloading in Scala when type parameters are being used
- Why doesn't Scala fully infer type parameters when type parameters are nested?
- Scala is unable to type check when higher kinded types are used
- Difference between F[_] and F[T] In Scala when used in type constructors
- Can a Scala type parameter reference itself when used as a parameter to a base-class?
- What Scala concepts are being used to make Scalatra DSL work?
- Why are the bounds of type parameters ignored when using existential types in Scala?
- Why does Scala not infer the type parameters when pattern matching with @
- Accounting for type parameters in a Scala generic class 'equals' method... are manifests the only way?
- Excluding type evidence parameters from analysis in Scala when using -Ywarn-unused
- Trait runtime type of type parameter through TypeTag when used with Existential type in Scala
- Why the following Scala code does not compile unless explicit type parameters are added?
- Scala "takes no type parameters, expected: one" when using type parameters
- Scala implicit ordering error when not specifying type parameters
- Scala variable number of parameters that are sub-classes of an F-Bounded type
- Why is Scala unable to infer the type of an anonymous function when there is method overloading and only one method takes a function?
- What are the rules for when trait/class type parameters take precedence vs method type parameters
- Advice on refactoring Scala - can I eliminate vars that are being used in foreach loops
- How to pass type parameters to my scala application? Are factories the best solution?
- Spark Scala UDF not returning expected value when the parameters are empty
- Why scala type inference loses efficacy when there are overloaded functions with same num of parameters?
- scala sbt test-only parameters are only picked up when run from sbt shell
- Scala type mismatch in function which returns Double => String when "return" keyword is used
- Why Type Check Error are not detected when Pattern Matching on Generic Type in Scala
- Are the terms Type and Class used interchangeably - Scala
- Can wildcard anonymous functions be used when parameters are repeating in the result expression?
- How to limit type parameters of methods when instantiating traits in Scala
- What are type lambdas in Scala and what are their benefits?
- What are the relationships between Any, AnyVal, AnyRef, Object and how do they map when used in Java code?
- What are type classes in Scala useful for?
More Query from same tag
- Apache Flink - Tweet Vectorization for SVM
- Is the Streaming k-means clustering predefined in MLlib library of spark supervised or unsupervised?
- Create dataframe where no. of rows based on splitting array into 'n' batches in Spark
- Reliably working out if your db is down with Scala Slick
- Scala Tuple not show type mismatch if passing parameter inline
- Why does Haskell's foldr NOT stackoverflow while the same Scala implementation does?
- How to get first element from Any
- How to fetch from one stream first and then pass to another stream
- iterate over case class data members
- "=>" operator in Scala
- FS2 through2 closing all resources when the first stream is finished?
- In current Scala, is there a cleaner way to do the "lazy constructor pattern"
- How to stop Eclipse / Scala IDE from uploading all my projects at once?
- flattening future of option after mapping with a function that return future of option
- On Windows, mvn jetty:run is fine but mvn jetty:run-war fails
- Scala IDE 4.0.0 thinks there's errors in an out-of-the-box Play Framework 2.3.7 program
- Scala: is it possible to restrict access to the function definitions of a trait to its direct callers?
- How can I perform dynamic reconfiguration in Scala (like Dyre or XMonad)?
- One JsPath.read in Reads[T] definition does not compile. Two or more do
- How to set and get keys from scala TreeMap?
- How to efficiently find distinct values from each column in Spark
- Weird type inference in scala
- Merge two arrays based on first element
- Mapped explicitly for geo_point using scala
- Scala variable scope and for loops
- Representation of a Seq with only one element?
- Play Framework - System.loadLibrary() only once per thread
- Creating and accumulating a Map of Map of Map ... in scala
- Interesting behaviour with infix notation
- How to get dependency version from Scala Play! framework build file