我正在查看一些应用程序的源代码,我遇到了这段代码,但我无法理解这是什么。
public enum XStreamUserType {
MES_CONFIG_XSTREAM(MESConstants.MES_CONFIG_XSTREAM_USER, "MES_CONFIG_XSTREAM_USER", new XStream());
private int userTypeId;
private String userType;
private XStream xStream;
private XStreamUserType(int userTypeId, String userType, XStream xStream) {
this.userTypeId = userTypeId;
this.userType = userType;
this.xStream = xStream;
switch (this.userTypeId) {
case MESConstants.MES_CONFIG_XSTREAM_USER:
loadConfigReader();
break;
default:
}
}
这一行是什么意思?
MES_CONFIG_XSTREAM(MESConstants.MES_CONFIG_XSTREAM_USER, "MES_CONFIG_XSTREAM_USER", new XStream());
最佳答案
根据JLS-8-9 ,
The Identifier in a EnumConstant may be used in a name to refer to the enum constant.
An enum constant may be followed by arguments, which are passed to the constructor of the enum type when the constant is created during class initialization as described later in this section. The constructor to be invoked is chosen using the normal overloading rules (§15.12.2). If the arguments are omitted, an empty argument list is assumed.
所以所以
MES_CONFIG_XSTREAM(MESConstants.MES_CONFIG_XSTREAM_USER, "MES_CONFIG_XSTREAM_USER", new XStream());
代表一个标识符,它是您通过调用的
类 私有(private)构造函数
声明的第一个枚举常量(而且似乎是唯一一个) >enumXStreamUserType
具有以下签名:
private XStreamUserType(int userTypeId, String userType, XStream xStream)
我认为MESConstants.MES_CONFIG_XSTREAM_USER
被评估为int
,“MES_CONFIG_XSTREAM_USER”
是一个String
并且new XStream()
是一个XStream
(您可以看到与构造函数的匹配)
正确定义后,您可以进一步使用新创建的枚举:XStreamUserType.MES_CONFIG_XSTREAM
关于java - 这是函数、变量还是其他东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19356451/