Monday 16 January 2012

Java : Static Import statements.

Importing the static class is use full instead using them all the time we use them to call their static methods.

E.g:

import static org.junit.Assert.*;

The above helps in using Assert methods directly into the code as below,

A sample class from Junit.

package com;

import static org.junit.Assert.*;

import org.junit.Test;

public class WelcomeTest {
@Test
public void testSayHello() {
 Welcome welcome = new Welcome();
 assertEquals("Hello", welcome.sayHello());
}
}

No comments:

Post a Comment