0

What does static mean in

import static org.mockito.Mockito.*;

I have seen statements like import java.util.*; but it never had static.

Thank you

Tibrogargan
  • 4,508
  • 3
  • 19
  • 38
Steven
  • 11
  • 3

2 Answers2

1

static is a Java keyword (not specific to Mokito). Statically importing a class allows you to use class members from the imported class without qualification.

So instead of doing something like this:

if (foo == Answers.CALLS_REAL_METHODS) {

You can do:

if (foo == CALLS_REAL_METHODS) {
Tibrogargan
  • 4,508
  • 3
  • 19
  • 38
0

According the the documentation,

  1. The normal import declaration imports classes from packages, allowing them to be used without package qualification,
  2. The static import declaration imports static members from classes, allowing them to be used without class qualification.

You can use it when you require frequent access to static members from one or two classes.

Raman Sahasi
  • 30,180
  • 9
  • 58
  • 71