dagblog.
← Archive

Eclipse tips and tricks — Static imports


How many times have I typed import static org.junit.Assert.* while writing tests, only to write assertThat in a test method and curse because I still have to import other static methods? There’s a much easier way. Eclipse lets you add methods from selected types to Content Assist, which then suggests them even when the type hasn’t been imported in the class. When you use a method, Eclipse adds the import to the class automatically.

Archive image in Eclipse tips and tricks — Static imports, figure 1
Image could not be loaded. Archive image in Eclipse tips and tricks — Static imports, figure 1
↗ Medium

Go to Window >> Preferences >> Java >> Editor >> Content Assist >> Favorites. Use New Type to add an entire type and all its static methods, or New Member to add just the methods you want.

Archive image in Eclipse tips and tricks — Static imports, figure 2
Image could not be loaded. Archive image in Eclipse tips and tricks — Static imports, figure 2
↗ Medium

Medium version

Related articles

Related CZ Podcast episodes