import static

you may face a situation when you need some static members and methods from a few classes, but you prefer not to mention those full qualification class name as a reference for getting access to static fields/or methods. The solution is by using import static, instead of regular import .

one of the most common examples is JUnit methods.

import static org.junit.Assert.*;
import org.junit.Test;

public class MyObjectTest {

    public void shouldReplaceItem() throws Exception {
        fail("Not yet implemented");


you can see by adding static import at the beginning, calling the fail method or other Assert-related methods could be easier and more readable.

Reference: Java Oracle Documentation.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s