Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is simply not possible, in the exact way you describe it.</p> <p>When you reference static objects, you refer to the class that those objects are declared in. Quite simply, if you declare a constant in the <code>NetworkParameters</code> class, it does not exist in the <code>Parameters</code> class and is not accessible as such.</p> <p>Separating vast numbers of parameters into different containing classes (which don't need to be subtypes of each other as this achieves nothing) is quite good practice and often used. Why do you have such an aversion to just using <code>NetworkParameters.POST_NUM</code>, as this is the name of the parameter and sounds completely sensible to me?</p> <p>One thing that may help you (depending on your own tastes) is to use Java 5's <a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/static-import.html" rel="nofollow noreferrer">static import</a> feature. If, at the top of a class file, you declare</p> <pre><code>import static the.package.name.Parameters.*; import static other.package.NetworkParameters.*; </code></pre> <p>then you will be able to use all of the constant names from both classes without any prefix at all. This is often quite nice when it's obvious what comes from where - but it can become a nightmare if you're statically importing from a few classes, <em>especially</em> if you don't have an IDE to work out the reference for you.</p> <p>But again - <strong>why</strong> do you want to reference them as <code>Parameters.FOO</code>, but want them to live in a separate class? Either approach (everything in one file, different constants in different files) is good and fine if you do it completely, but you can't magically change the laws of Java references because you don't like the look of them. :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload