将值设置为枚举 - Java
我正在尝试在我的 java 应用程序中将值设置为枚举......但我不能这样做。
我做错了吗???
public enum RPCPacketDataType {
PT_UNKNOWN(2),
PT_JSON(4),
PT_BINARY(5)
};
它给了我这个错误:构造函数 RPCPacket.RPCPacketDataType(int) 未定义。
I'm trying to set values to enum in my java application....but I can't do that.
Am I doing it wrong???
public enum RPCPacketDataType {
PT_UNKNOWN(2),
PT_JSON(4),
PT_BINARY(5)
};
It's giving me this error : The constructor RPCPacket.RPCPacketDataType(int) is undefined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您还可以像在“普通”类中一样在枚举上定义方法。
You can also define methods on your enum as you would in a "normal" class.
您应该创建一个接受
int
参数的构造函数。还要添加一个int
字段来保存传递的值。You should create a Contructor which accepts an
int
parameter. Also add anint
field which will hold the passed value.正如 #emboss 和 #Michael 所说的正确,你可以使用接受 ant
int
的构造函数As both #emboss and #Michael said correctly you can use a Contructor which accepts ant
int