Javadoc 1.5 和 1.6 中缺少 enum.valueOf(String name)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9803917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
enum.valueOf(String name) missing from Javadoc 1.5 and 1.6
提问by Kimberley Coburn
This is probably a stupid question, but I'm using the method enum.valueOf(String name)
. No problem there, except that when I was checking the javadoc to find out more about this method, I couldn't find it. There is javadoc for valueOf(Class<T> enumType, String name)
but none for enum.valueOf(String name)
(which would suggest that a method with this signature doesn't exist - but clearly it does).
这可能是一个愚蠢的问题,但我正在使用方法enum.valueOf(String name)
。没问题,除了当我检查 javadoc 以了解有关此方法的更多信息时,我找不到它。有 javadoc for valueOf(Class<T> enumType, String name)
but none for enum.valueOf(String name)
(这表明具有此签名的方法不存在 - 但显然它确实存在)。
Am I missing something here, or is this an oversight in the javadoc for the API?
我在这里遗漏了什么,或者这是 API 的 javadoc 中的疏忽?
Thanks
谢谢
采纳答案by Peter Lawrey
There is no method Enum.valueOf(String) However, every enum
has a values()
and valueOf(String)
method generated by the compiler and these are documented. They are static methods and thus cannot be overridden or defined in a super class or interface.
没有方法 Enum.valueOf(String) 但是,每个方法enum
都有由编译器生成的values()
andvalueOf(String)
方法,并且这些方法都有文档。它们是静态方法,因此不能在超类或接口中覆盖或定义。
Enum e = Enum.valueOf(""); // this doesn't compile
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.State.html#values%28%29
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.State.html#values%28%29
http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.State.html#values%28%29
http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.State.html#values%28%29
Its the same in Java 5.0, 6 or 7.
它在 Java 5.0、6 或 7 中相同。
For Java 5.0 http://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#8.9(search for values) For Java 7 http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.9.2provided by @kapep
对于 Java 5.0 http://docs.oracle.com/javase/specs/jls/se5.0/html/classes.html#8.9(搜索值)对于 Java 7 http://docs.oracle.com/javase/规格/jls/se7/html/jls-8.html#jls-8.9.2由@kapep 提供
回答by Bohemian
Under the hood, enum.valueOf(String name)
is actually calling Enum.valueOf(Class<T> enumType, String name)
在引擎盖下,enum.valueOf(String name)
实际上是在调用Enum.valueOf(Class<T> enumType, String name)