Java – a better way to call a function multiple times
•
Java
See English answers > performance of static methods vs instance methods3
>Create the object only once and call the function with it
StringManipulation sm = new StringManipulation();
sm.reverse("something");
sm.addPadding("something");
sm.addPeriod("something");@H_403_6@
要么
>每次都直接打电话给班级
StringManipulation.reverse("something");
StringManipulation.addPadding("something");
StringManipulation.addPeriod("something");@H_403_6@
Solution
The performance difference between the two options is negligible But the main difference lies in the usage of the method
If you need a method to perform any general tasks unrelated to class objects, you will consider static methods in your design For object - dependent tasks, you should consider instance methods
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
