I'm analyzing a code and I found the class Constantes
, which, as its name suggests, has this structure:
public final class Constantes {
public static final String PREFIJO = "prefijo_";
}
In another class I saw this import
:
import static mi.paquete.Constantes.*;
So, by using the attributes of the constant class it does it directly by its name,
String nombreFichero = PREFIJO + nombre;
No need to reference the class as with normal imports:
String nombreFichero = Constantes.PREFIJO + nombre;
I did not know the technique of import static
and it seems quite interesting to clean code, as long as:
- Your application is well structured
- Use with head
- Do not create confusion because you know where the constants come from.
But:
- Is there any contraindication when using this technique?