它可能是两件事,一个枚举器(AKA Enum)或一个包含常量字段的类。
枚举示例:
public enum ValueSeperationType {
CSV(","),NEW_LINE("\n"),DASH("-"),DOT("."),SPACE(" "),TAB("\t"),OTHER("_"); //Our values, the parenthesis with the string in it is the value the constructor will get once the enum is called.
private final String seperator; //A variable to hold the value provided to the constructor by the enum;
ValueSeperationType(String seperator){// the constructor that gets called when we type for instance "CalueSeperationType.CSV" Then the constructor takes as parameter a String with value ",".
this.seperator = seperator;// initialising the variable to hold the value.
}
public String getSeperator(){ // a method allowing user to get the seperation value, If we type ValueSeperationType.DASH.getSeperator() this will return "-".
return this.seperator;
}
//You can add as many parameters in the constrctor as you want, as many variables and methods as you want.
}
另一种可能性是它是一个包含常量字段的类。 (虽然这不太可能,因为这不是正确的命名约定,但是......你永远不知道。)
所以一个带有常量字段的类的例子:
class ValueSeperation{
public static final String CSV = ",";
public static final String NEW_LINE = "\n";
public static final String DASH = "-";
public static final String DOT = ".";
public static final String SPACE = " ";
public static final String TAB = "\t";
public static final String OTHER = "_";
//Same concept as above, in a more direct way... here you simply invoke ValueSeperation.CSV and that returns ",". Each method has it's benefits and it is up to the developer to decide what to implement depending on the senario.
}
希望对你有所帮助。