enum.valueOf(String name) missing from Javadoc 1.5 and 1.6

泄露秘密 提交于 2019-12-03 06:49:55

问题


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).

Am I missing something here, or is this an oversight in the javadoc for the API?

Thanks


回答1:


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

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

Its the same in Java 5.0, 6 or 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.2 provided by @kapep




回答2:


Under the hood, enum.valueOf(String name) is actually calling Enum.valueOf(Class<T> enumType, String name)



来源:https://stackoverflow.com/questions/9803917/enum-valueofstring-name-missing-from-javadoc-1-5-and-1-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!