Sam Stewart

Ramblings of a discombobulated programmer

10 notes &

Calling static methods in Java

When calling static methods in Java, make sure you always use the class prefix even if you are within the declaring class. For example, imagine you have a static method called addLoader and you are calling it within the URLLoader class where it is declared. 

While you could simply call addLoader(…) without the class name, you should include the class name instead: URLLoader.addLoader(…). By always prefixing, you clarify the type of method as static. Otherwise, anyone reading our code could fairly assume another instance method.

Filed under best practices java programming

  1. samthestewart posted this