Reputation: 6431
I'm using JRebel with Scala and I'm quite frequently experiencing the need for restart of server due to the fact that JRebel is unable to load a class if the superclass was changed. This is done mainly when I change anonymous functions as I can deduce from the JRebel error desription: Class 'mypackage.NewBook$$anonfun$2' superclass was changed from 'scala.runtime.AbstractFunction1' to 'scala.runtime.AbstractFunction2' and could not be reloaded
.
Is there any way, how can I design my code to avoid this? Does scala compiler take the functions, numbers them from one as they appear in source code?
Upvotes: 1
Views: 272
Reputation: 21017
The numbers that are changing refer to the number of function arguments. An AbstractFunction1
is a one-argument function, while AbstractFunction2
is a two-argument function. One way to work around this would be to curry or tuple your functions so that they're always one-argument functions.
And, yes, anonymous functions are automatically named as you suggested. If you insert a new anonymous two-arg function before an existing anonymous one-arg function, it will appear as if the type of the original function changed.
Upvotes: 2