[英]Boolean.getBoolean() Vs System.getenv() in Java
Boolean.getBoolean("myvariable"); // where myvariable has been defined in the
// Environment variable as Variable name:
// myvariable
// and Variable Value:true
上面的調用使我的輸出為false
。 如果我用
System.getenv("myvariable") ;
然后它給我的輸出為true
。
我想知道為什么Boolean.getBoolean("myvariable")
無法正常工作。
System.getenv
返回一個環境變量 。 這與返回Java系統屬性的 System.getProperty
。
Boolean.getBoolean
使用后一個調用,如記錄所示:
當且僅當由參數命名的系統屬性存在並且等於字符串“ true”時,才返回true。 [...]可通過
getProperty
來訪問系統屬性,該屬性是System類定義的方法。
Boolean.getBoolean("myvariable");
尋找一個名為myvariable的系統屬性,而System.getenv("myvariable");
尋找一個環境變量。 盡管相似,但它們並不相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.