× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Get all static variables of a class without reflection

Francis Galiegue
Apr 23, 2015
<p>Maybe you can go through an interface:</p> <pre><code>public interface FaultCodeProvider { String getFaultCode(); } </code></pre> <p>Then have your enums implement it:</p> <pre><code>public enum DefaultFaultCodes implements FaultCodeProvider { FAULT1("text for fault 1"), // etc ; private final String value; DefaultFaultCodes(final String value) { this.value = value; } @Override public String getFaultCode() { return value; } } </code></pre> <p>Collecting them from the enum is then as easy as cycling through the enum's <code>values()</code>.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/29650374/Get%20all%20static%20variables%20of%20a%20class%20without%20reflection/29650463">Stack Overflow</a>.</p>
comments powered by Disqus