StringTokenizer method equivalence

前提是你 提交于 2019-12-02 22:01:59

问题


Why do hasMoreElements and hasMoreTokens return the same value?


回答1:


From the javadoc of hasMoreElements()

/** 
* Returns the same value as the hasMoreTokens
* method. It exists so that this class can implement the
* Enumeration interface.
*/

Javadoc




回答2:


since this is a legacy class which implements Enumeration it also uses the method hasMoreTokens for simplicity method naming.

In simple case which uses just the StringTokenizer you can use the hasMoreTokens method. In polymorphic case which you created or already has more implementation of the Enumeraion interface you will use the hasMoreElements which is part of the Enumeraion interface.



来源:https://stackoverflow.com/questions/6814888/stringtokenizer-method-equivalence

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