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 why we cannot have a top level static class. If I want to create a class containing only utility methods, I can go for static class. Any reason why developers of Java restricted this feature ?
解决方案
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
}
}