Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom error message for missing default constructor #29

Closed
stephanos opened this issue Jul 14, 2011 · 1 comment
Closed

custom error message for missing default constructor #29

stephanos opened this issue Jul 14, 2011 · 1 comment

Comments

@stephanos
Copy link

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!

@debasishg
Copy link
Owner

Fixed on master ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants