Created
July 11, 2012 01:45
-
-
Save JoshRosen/3087424 to your computer and use it in GitHub Desktop.
Do Scala type parameter names matter?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JavaTypeParamNamespace { | |
public static void main(String[] args) { | |
// This should compile: | |
new MyClassRenamedTypes<Integer>().map(1, new MyArgument<String>("String")); | |
// This fails with the error | |
// JavaTypeParamNamespace.java:8: <U>map(U,MyArgument<U>) in MyClass<java.lang.Integer> cannot be applied to (int,MyArgument<java.lang.String>) | |
new MyClass<Integer>().map(1, new MyArgument<String>("String")); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait MyTrait[T] { | |
def map[U](t: T, u: MyArgument[U]) : MyArgument[U] = u | |
} | |
class MyArgument[U](u: U) {} | |
class MyClass[U] extends MyTrait[U] {} | |
class MyClassRenamedTypes[U2] extends MyTrait[U2] {} | |
object MyClass { | |
def main(args: Array[String]) { | |
new MyClass[Int].map(1, new MyArgument("String")) | |
new MyClassRenamedTypes[Int].map(1, new MyArgument("String")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://issues.scala-lang.org/browse/SI-6057