Should a static static class use only static methods?

I have a class with only static methods. Should the class itself become static? Does it matter?

+4
source share
2 answers

Does it matter?

Creating a static class ensures that it can never be created by generating a compiler error if the user tries to do this. If a class consisting only of static elements is simply not intended to be instantiated, there is no reason not to put it. You may not do this, but examples of such a class will not be very useful, and users creating these instances will be left in confusion.

, , , , , , (, , ).

+6

: .

, static. , , . , ( ..), .


public static class A 
{
  // Some static member
}

A a = new A(); // Compilation error
+2

All Articles