Mixing private and public/protected methods of the same name causes multimethods to be disabled and is forbidden to avoid surprising behaviour
Asked Answered
P

1

8

I just upgraded one of my Grails apps to 2.2.0 which is using Groovy 2.0 and I am now getting this compile error:

Mixing private and public/protected methods of the same name causes multimethods to be disabled and is forbidden to avoid surprising behaviour. Renaming the private methods will solve the problem.

Based on the following code:

def getRootDomain(key) { }

private getRootDomain() { }

It's an easy fix but I'd really like to understand the why better. Can someone explain this to me?

Postremogeniture answered 15/1, 2013 at 13:40 Comment(0)
S
8

It's because of the way groovy chooses which method to call, and its potential incompatibility with java.

Have you seen this thread on the mailing list?

http://groovy.329449.n5.nabble.com/mixing-public-private-overloaded-methods-causes-compilation-error-td367147.html

Susurrus answered 15/1, 2013 at 14:7 Comment(3)
I had not seen that. Thanks.Postremogeniture
This link is broken: groovy.329449.n5.nabble.com/…Glanville
Both links are broken, please post the answer on SO instead of just links!Casein

© 2022 - 2024 — McMap. All rights reserved.