The wrapper class Integer has the static method parseInt() which is used like this:
Integer.parseInt();
I thought only methods of static classes could be called like this (i.e. Class.doMethod()). All non-static classes need objects to be instantiated to use their methods.
I checked the API, and apparently Integer is declared as public final Integer – not static.
Any class can contain both
staticand non-static methods. When calling thestaticmethods on any class – including your own – you don’t need to instantiate an instance of the class, just call the method using the class name:MyClass.methodName().In fact, even the following will work:
This works because only the class type of the reference is important when calling
staticmethods. But consider this poor style: always use e.g.Integer.parseIntinstead.Also note that you can’t declare a top-level class as
staticanyway: only nested/inner classes can be declared as static.