'What does Scala mean by Suspicious Type Shadowing?
I'm implementing a scala Set, and I'm getting this error from this code
Suspicious shadowing by a Type Parameter: A
def remove[A](elemToRemove: A): MySet[A]
^
which for some reason, the language hates this generic A I'm passing it, why is that? and what does it mean by "Suspicious shadonwing"?
https://scastie.scala-lang.org/NwcMObgnSxGjXA2clmaEyA, though scastie is running into a different error, if you remove the [A] from remove[A] it will pass and execute
type mismatch;
found : exercises.part2afp.MySet[A(in class NonEmptySet)]
required: exercises.part2afp.MySet[A(in method remove)]
Solution 1:[1]
This is the context:
case class EmptySet[A]() extends MySet[A] {
override def remove[A](elemToRemove: A): MySet[A] = this
The problem is that the A in remove[A] is a different type from the A in EmptySet[A].
If you want these to be different types, use different letters.
If it is supposed to be the same type, delete the [A] from remove.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tim |
