问题描述
这可能是一个愚蠢的问题,但是我使用方法 enum.valueOf(String name)
。没有问题,除了当我检查javadoc以了解更多关于这个方法,我找不到它。有 valueOf(Class< T> enumType,String name)
的javadoc,但对于 enum.valueOf(String name)
(这将表明一个具有此签名的方法不存在 - 但显然它是这样)。
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).
我在这里缺少一些东西,或者是在javadoc for API?
Am I missing something here, or is this an oversight in the javadoc for the API?
谢谢
推荐答案
没有方法Enum.valueOf(String)然而,每个枚举
有一个 values()
和 valueOf字符串)
由编译器生成的方法,并记录这些方法。它们是静态方法,因此不能在超类或接口中被覆盖或定义。
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 e = Enum.valueOf(""); // this doesn't compile
它在Java 5.0,6或7中是相同的。
Its the same in Java 5.0, 6 or 7.
对于Java 5.0 (搜索值)
对于Java 7 由@kapep提供
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.2 provided by @kapep
这篇关于从Javadoc 1.5和1.6中缺少enum.valueOf(String name)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!