I recently was working on an application where I needed to verify that certain static constants were defined by a specific class. I have run into similar situations like this before so I decided to write a simple utility which I could reuse.
ConstantDefinitionUtil is an all static class which provides an API for determining if specific constants have been defined by a class.
Additionally, ConstantDefinitionUtil provides a method for retrieving all static constants which have been defined by a class.
The following example demonstrates how ConstantDefinitionUtil can be utilized to determine if the static constant “X” has been defined by ClassA:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | package { public class ClassA { public static const X:int = 1; public static const Y:int = 2; public static const Z:int = 3; } } import com.ericfeminella.utils.ConstantDefinitionUtil; trace( ConstantDefinitionUtil.isDefinedBy("X",ClassA) ); //true |
{Sorry, Comments are currently Closed! }