[英]How to create a Variable with scope global and but should not be a STATIC
[英]How to Create a Global Variable with a condition
我想创建一个全局变量,但我希望它是基于机器操作系统的两个值之一。 我想我可以通过编写以下代码来做到这一点:
import java.lang.*;
import java.util.Properties;
public class constants {
public static String driverFile = null;
public static String storageDirectory = null;
if (System.getProperty("os.name").startsWith("Windows")){
storageDirectory = "C:\\Scripts\\Price_Tracker";
driverFile = "geckodriver-v0.27.0-win64.exe";
}else{//is linux
storageDirectory = "/Price_Tracker";
driverFile = "geckodriver-v0.27.0-linux64";
}// end if(System.getProperty("os.name").startsWith("Windows")
}//end public class constants
但我收到一条错误消息,说“无法解析符号‘getProperty’ ”,我想要做的甚至可能吗?
public class constants {
public static String driverFile = null;
public static String storageDirectory = null;
static {
if (System.getProperty("os.name").startsWith("Windows")){
storageDirectory = "C:\\Scripts\\Price_Tracker";
driverFile = "geckodriver-v0.27.0-win64.exe";
}else{//is linux
storageDirectory = "/Price_Tracker";
driverFile = "geckodriver-v0.27.0-linux64";
}// end if(System.getProperty("os.name").startsWith("Windows")
}
}//end public class constants
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.