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
I recently forgot to define a default constructor (when using reflection) and had a hard time discovering what I did wrong. The error message was "next on empty iterator" coming from:
def newInstance[T](clazz: Class[T])(op: T => Unit): T = {
val constructor =
clazz.getDeclaredConstructors.filter(_.getParameterTypes.length == 0).head
Maybe you could turn it into something like:
def newInstance[T](clazz: Class[T])(op: T => Unit): T = {
val constructor =
clazz.getDeclaredConstructors.filter(_.getParameterTypes.length == 0)
.headOption.getOrElse(sys.error("no default constructor found on " + clazz))
This way it would be much easier to find the reason for the exception!
Cheers!
The text was updated successfully, but these errors were encountered:
I recently forgot to define a default constructor (when using reflection) and had a hard time discovering what I did wrong. The error message was "next on empty iterator" coming from:
Maybe you could turn it into something like:
This way it would be much easier to find the reason for the exception!
Cheers!
The text was updated successfully, but these errors were encountered: