Where answers come from

Some pages can ask a language model questions. Set this up once; your choice is remembered in this browser for the whole site.

Model source
Use another source instead
You sign in on OpenRouter; it gives this page a key for your account.

Importing Public Static Methods

Originally published .

Consider the way you get “assertNotNull” into a JUnit4 test. You do it like this:


import static org.junit.Assert.assertNotNull;

import static org.junit.Assert.assertNull;

import static org.junit.Assert.assertTrue;

The public static methods of the class Assert are pulled into your lexigraphical context and now you can write code like this in your methods:


@Test

public void testStringyGoodness() throws Exception {

  String next = null;

  assertNull(next);

  next = "foo";

  assertNotNull(next);

  assertTrue(next.equals(foo));

}

And, all of this is relatively simple… but is it good? I guess that the Object Oriented Paradigm is so well established now that we can do things like this in the language and not expect “old skool” programmers to immediately break things with it.

Explore the map · Browse by topic and date