Overriding a method can be prevented by using the keyword final, likewise how to prevent overloading?
Overriding a method can be prevented by using the keyword final , likewise how
Share
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.
You can’t do that in Java.
An overloaded method is basically just another method.
An attempt could look (something) like this
but it won’t work since Java resolves overloading by looking at the “best match” or “most specific signature”.
The method could still be overloaded with a
which would be called when doing
yourMethod("hello", "world").Btw, why would you want to prevent overloading? Perhaps there is another way of doing what you want?