Scala is the same as Java in this respect, and the following from the "Names" chapter of the Java specification applies:
A declaration d of a type named n shadows the declarations of any other types named n that are in scope at the point where d occurs throughout the scope of d.
So the type parameter for a method will always shadow a class or trait type parameter with the same name. Your
Foo example demonstrates this fact.
The apparent counterexample you're seeing in the case of
foldLeft is just an unpleasant artifact of the current version of Scaladoc, as is pointed out in the answers to the question you've linked.
foldLeft isn't defined in the
Map trait, but in
TraversableOnce, where there isn't a trait type parameter named
B at all.
In general shadowing the type parameter of a trait or class in a method is a really bad idea, of course.
- What are the rules for when trait/class type parameters take precedence vs method type parameters
- What is the purpose of using type parameters for an empty trait when extending it?
- What are the rules for precedence when it comes to choosing an implicit to use for the CanBuildFrom function
- What are the precise rules for when you can omit parenthesis, dots, braces, = (functions), etc.?
- Accounting for type parameters in a Scala generic class 'equals' method... are manifests the only way?
- Method signature clashes when class and its parameters extends from the same trait
- What special rules does the scala compiler have for the unit type within the type system
- What happens to a variable assignment when I call a method that returns an instance of a case class holding the said variable?
- Why are the bounds of type parameters ignored when using existential types in Scala?
- What are the scope rules for lazy vals in Scala?
- In Scala, what are the rules for making closures with underscores?
- Is there are way to create a generic class with a trait or mixin that is a subtype of the type parameter
- Why doesn't Scala's implicit class work when one of the type parameters should be Nothing?
- What is the best way to assert for a scala method whose return type is Future[Unit]
- scala: what is the inner class method for dynamic scoping?
- What is the good code style for scala when calling a method of an object
- In Scala, how to use reflection to get the real type of varargs parameters for method
- difficulty when using contravariant type parameters for both a type parameter and return type of a method
- When using the gson library for converting a Scala class to a string, UTF-8 characters are not escaped
- What is the syntax for Single Abstract Method with generic types in a trait
- What is the first of the two type parameters of the function passed to a `collect` method in Scala?
- What are the suitable problems for Akka vs Gridgain? When is one more suitable than the other?
- scala: using method of extending class based on macros invokes trait default impl if type of instance is statically the base class
- What are the rules for writing a sort comparator
- How can I implement concrete class which extends trait defining a method with type by the type parameter's type alias
- what is the data type of object when passing to another class in scala ? or how to pass an object type as a parameter to another class?
- What is the best design for set of elements with different type parameters in Scala
- What are the best use cases for Akka framework
- What are some compelling use cases for dependent method types?
- What are the relationships between Any, AnyVal, AnyRef, Object and how do they map when used in Java code?
More Query from same tag
- Play 2 - templates without helpers
- why the error is given while reading the text file in spark
- How to parse json schema with list of objects in spark streaming?
- Spark Sql UDF throwing NullPointer when adding a filter on a columns that uses that UDF
- Scala REPL: find where given class / trait is defined
- Scala relfection, finding type parameters of subtypes
- Is there way to work with separated Play! 2 libraries in another scala project?
- What replaces class variables in scala?
- jasypt digest implementation in PHP
- query JSON data using slick(pg)
- Extract numbers from string with rich string magic
- How to convert GetResponse from elastic4s to specific case class?
- Scala path dependent return type from parameter
- Efficient load CSV coordinate format (COO) input to local matrix spark
- scala nested for-loop not working properly
- using datetime/timestamp in scala slick
- How does promise linking work in Scala and why is it necessary?
- Checking the equality of types involving existentials in Scala
- Stuck on getting access token from Twitter API using Scala
- How to write a generic function to evaluate column values inside withcolumn of spark dataframe
- Stop processing maps in Scala
- Scala Option.orElse in Java
- Scala: Map list elements to a function of another list elements
- Error : RDD transformations and actions can only be invoked by the driver, not inside of other transformations
- scala's for yield comprehension used with Future. How to wait until future has returned?
- Seq.contains in SQL in Spark Dataframe
- Composing Functions Leads to StackOverflow
- Scala recursion vs loop: performance and runtime considerations
- Hash the contents of an columntype Array[Int] individually
- Scala - Pass in Seq to method that takes in _*