-
Notifications
You must be signed in to change notification settings - Fork 31
Closed
Description
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!
Metadata
Metadata
Assignees
Labels
No labels