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
The following code will not compile because it can't match the types method types.
classColl[E] extends java.util.Collection[E] {
deftoArray[T](a: Array[T]):Array[T] =???
...
}
--Error:Coll.scala -----------------------------------------------------------2|deftoArray[T](a: Array[T]):Array[T] =???|^|overriding method toArray in traitCollection of type [T] => (x$0: Array[T])Array[T];
| method toArray of type [T] => (a: Array[T])Array[T] has incompatible type--Error:Coll.scala -----------------------------------------------------------1|classColl[E] extends java.util.Collection[E] {
|^|classColl needs to be abstract, since deftoArray: [T] => (x$0: Array[T])Array[T] is not defined
|(Note that Array[T] does not matchArray[T]: their typeparameters differ)
two errors found
The same happens when trying to override the method:
classColl[E] extends java.util.AbstractSet[E] {
overridedeftoArray[T](a: Array[T]):Array[T] =???
...
}
--Error:Coll.scala -----------------------------------------------------------2|overridedeftoArray[T](a: Array[T]):Array[T] =???|^|overriding method toArray in classAbstractCollection of type [T] => (x$0: Array[T])Array[T];
| method toArray of type [T] => (a: Array[T])Array[T] has incompatible type
one error found
The text was updated successfully, but these errors were encountered:
If one of two method types originates from Java, the two
types might match yet have different parameter signatures,
because of the way Array[T] is handled differently in Java
and Scala. The tweak takes this pecularity into account.
The following code will not compile because it can't match the types method types.
The same happens when trying to override the method:
The text was updated successfully, but these errors were encountered: