In the class or object body, this works:
def a(s:String) {}
def a(s:Int) {}
But if it is placed inside another method, it does not compile:
def something() {
def a(s:String) {}
def a(s:Int) {}
}
Why is it so?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note that you can achieve the same result by creating an object:
In your example, you define local functions. In my example, I’m declaring methods. Static overloading is allowed for objects, classes and traits.
I don’t know why it’s not allowed for local functions but my guess is that overloading is a possible source of error and is probably not very useful inside a code block (where presumably you can use different names for in that block scope). I assume it’s allowed in classes because it’s allowed in Java.