Marc Tajchman <marc.tajch...@gmail.com> wrote on 02/20/2012 04:22:44 PM:
>
> I use a static field :
>
> class Debug {
> static val level : int = <some_value>;
> ....
> };
>
> Here the static field value is known at compile time (needs
> recompilation each time the value changes)
> Is it possible to specify it at run time ? The value may be
> different at each run, but remains constant during one run.
>
> I prefer to use a (global) static value so I don't have to propagate
> explicitely an object everywhere.
>
One trick that might suit your needs is to parse an environment value
during static initialization time as shown below.
--dave
import x10.util.Map;
public class Debug {
static val level:int = getIntValue("DEBUG_LEVEL", 0);
private static def getIntValue(k:String, defaultValue:int):int {
val env:Map[String,String] = System.getenv();
val value = env.getOrElse(k, null);
if (value == null) return defaultValue;
return Int.parse(value);
}
public static def main(Array[String]) {
Console.OUT.println("The debug level is "+level);
}
}
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users