You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider a Java implementation of the same main main() method:
public classJavaTypeParam {
public static void main(String[] args) {
// This should compile:newMyClassRenamedTypes<Integer>().map(1, newMyArgument<String>("String"));
// This fails:newMyClass<Integer>().map(1, newMyArgument<String>("String"));
}
}
Javac fails to compile the last line of this main() method:
{noformat}
JavaTypeParam.java:6: map(U,MyArgument) in MyClass<java.lang.Integer> cannot be applied to (int,MyArgument<java.lang.String>)
new MyClass().map(1, new MyArgument("String"));
^{noformat}
The only difference between MyClass and MyClassRenamedTypes is the name of the type parameter. It looks like type parameters in different namespaces are colliding.
Interestingly, everything compiles if MyArgument[U] is replaced by U. It also compiles if the definition of MyTrait.map() is changed to
The following Scala program compiles and runs without errors:
Consider a Java implementation of the same main main() method:
Javac fails to compile the last line of this main() method:
{noformat}
JavaTypeParam.java:6: map(U,MyArgument) in MyClass<java.lang.Integer> cannot be applied to (int,MyArgument<java.lang.String>)
new MyClass().map(1, new MyArgument("String"));
^{noformat}
The only difference between MyClass and MyClassRenamedTypes is the name of the type parameter. It looks like type parameters in different namespaces are colliding.
Interestingly, everything compiles if MyArgument[U] is replaced by U. It also compiles if the definition of MyTrait.map() is changed to
{code}
def map[U](u: MyArgument[U]) : MyArgument[U] = u{code}
The text was updated successfully, but these errors were encountered: