문제

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.

도움이 되었습니까?

해결책

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top