Question

Is it appropriate to use just the following import?

import groovyx.gpars.*

So that I can just do:

import groovyx.gpars.*

GParsPool.withPool {
   list = 1..10
   list.each{print it + 1 + "\n"}
}

Instead of:

import static groovyx.gpars.GParsPool.withPool

withPool {
   list = 1..10
   list.each{print it + 1 + "\n"}
}

Doing so I wouldn't have to mention every import like import static groovyx.gpars.actor.Actors.actor separately, like in this Hello World Example.

Was it helpful?

Solution

It's really a style issue, but at our company, we've decided that using * in import statements is asking for trouble later on. Using *, you're importing quite a few things, and you probably don't know what they all are. In this case, it might not be an issue, but using wildcard imports is pretty much guaranteed at some point to have you using a "Utils" class or some sort, and having no idea which package you're getting that from.

We even have a style violation for unused imports. Given today's IDEs with their very nice management of imports for you, there's not much justification for being lazy about your import statements and potentially making problems for future developers on your codebase (especially if it's you).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top