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
importscala.language.reflectiveCallsdefdouble[T](x: Any{def* (arg0: Int):T}) = x *2
double[Int](4)
causes the following exception:
java.lang.NoSuchMethodException: java.lang.Integer.$times(int)
at java.lang.Class.getMethod(Class.java:1778)
at .reflMethod$Method1(<console>:18)
at .double(<console>:18)
... 32 elided
However, it works as expected when I change the definition of double to:
defdouble(x: Any{def* (arg0: Int):Int}) = x *2
scala> double(4)
res21:Int=8
The text was updated successfully, but these errors were encountered:
@SethTisue said (edited on Sep 13, 2016 8:34:06 PM UTC):
note that structural types are AnyRef by default so an explicit "Any { ... }" is required here
The following code:
causes the following exception:
However, it works as expected when I change the definition of
double
to:The text was updated successfully, but these errors were encountered: