Мне вот что пришло в голову, что-то как-то так делать, на сколько это будет эффективно я не знаю...
config.properties:
PHP код:
#Config types:
boolean-BOOL=false
string-STR=Name
PHP код:
public class Config<Type> {
private static Map<String, Object> config = new ConcurrentHashMap<>();
private static String file = "C:\\config.properties";
public static void main(String[] args) throws IOException {
final Properties load = new Properties();
load.load(new FileInputStream(Config.file));
for (final Entry<Object, Object> entry : load.entrySet()) {
final String[] str = ((String) entry.getKey()).split("-");
if (2 == str.length) {
switch (str[0]) {
case "string":
Config.config.put(str[1], String.valueOf(entry.getValue()));
break;
case "boolean":
Config.config.put(str[1], Boolean.parseBoolean(String.valueOf(entry.getValue())));
break;
}
}
}
//Вывод:
System.out.println(Config.get("STR")); // String - Name
System.out.println(Config.get("BOOL")); // Boolean - false
}
public static <Type> Type get(final String key) {
return (Type) Config.config.get(key);
}
}
Но было бы очень удобно...
PHP код:
if("Name".equals(Config.get("STR"))) {
System.out.println(Config.get("STR")); // Name
}
if(Config.get("BOOL")) {
System.out.println(Config.get("BOOL")); // true
}