In Java, enumeration What do you mean?

What is enumeration? > meaning?

Is there any way to represent general purpose?

Solution

<?> Syntax is Java's way of specifying that a generic type is "unbounded" - that is, it can be "anything"

Enumeration Is an enumeration with unbounded type – you can assign any type of enumeration to such a variable, for example:

Vector<String> v = new Vector<String>();
Enumeration<String> es = v.elements();
Enumeration<?> e = es; // This assignment compiles OK

However, there is no limit to enumerating The nexterelement () method of The return type is object (even if it is actually an enumeration < string >), so you may need to cast:

String s = (String)e.nextElement(); // Unsafe cast - compiler warning

For background, enumeration is a typed interface with two methods hasMoreElements () and. Iterable and iterator replace the early (poor) attempts Some old classes use it, such as vector and stringtokenizer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>