What is the difference between ClassName.m() and (new ClassName()).m() m() is a static method.
What is the difference between ClassName.m() and (new ClassName()).m() m() is a static method.
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.
The difference is that in your second example you are creating an unnecessary object in memory.
It is still calling the same static method for the
ClassNameclass.It is recommended to use
ClassName.m()to avoid unnecessary object creation and to provide context to the developers indicating that a static method is indeed being called.