I am new to java. When I was going through language specification I found that static classes cannot be declared, but we can have static inner classes. I am little confused
It is not a restriction, you do not need static class
to define a utility class, you only need static methods
. For example the class Math
in java is full of static methods, but the class itself is not static.
You might only need static class when you define an inner class
that you want to use without creating an instance of the enclosing class, which is allowed in Java.
You can define your utility class as follows:
class Util {
public static void method(){
// your utility method
}
}