Static Import

One of the changes to the JavaLanguage in Java 5 was static import, which allows you to invoke static methods from classes without qualifying the method with the class name. Example:

    import static org.junit.Assert.*;

public class SimpleArithmeticTest { @Test public void additionHadBetterWork() { assertEquals( 7, 3 + 4 ); } }

assertEquals(), which lives on org.junit.Assert, has been statically imported. Without the static import, the test class would have to qualify the invocation by saying Assert.assertEquals(...).


CategoryJava


EditText of this page (last edited August 12, 2014) or FindPage with title or text search