What is the reason that helper class method is declared in static

why are all helper classes or utility classes declared in a static context?

Is this just for convenience, without creating every instance of the class every time?

will hit hard on the performance?

For instance:

DateHelper.getCurrentDate();
+4
source share
2 answers

Since they are not limited by state, they have one functionality that is purely stateless. For example, Math.abs(double a)it takes a double argument and returns an absolute value. So simple. So you do not need to do, for example, something like

Math m=new Math();
m.abs(12.33);

, , , static .

: - , . , static synchronized, , ( ) . , .

+7
-1

Source: https://habr.com/ru/post/1547397/


All Articles