Java - Generics - Collections - Upper Bound Wildcards
In this article, we will see how to use upper bounded Wildcards within Generics in Java.
Java Generic methods and generic classes enable programmers to specify, with a single method declaration, a set of related methods, or with a single class declaration, a set of related types, respectively. These classes are known as parameterized classes or parameterized types because they accept one or more parameters.
The question mark (?), represents the wildcard. It stands for unknown type in generics. When we want to restrict the kinds of types that are allowed to be passed to a type parameter, we can use that. For example, a method that operates on a class inherited from another class.
Upper bounded wildarcards is that when we want to restrict the kinds of types that are allowed to be passed to a type parameter.
To declare a upper bounded Wildcard parameter, list the ?, followed by the super keyword, followed by its lower bound.
Lets look to our class code.
class CL_servers
{
public String _vhostname;
public String _vOstype;
public CL_servers()
{
System.out.println("CL_server constructor is called..");
}
}
class CL_linuxServer extends CL_servers {}
class CL_linuxUbuntuServer extends CL_linuxServer{}
Lets see it in a java example.
In above example, we implemented our upper bound wildcard usage in our java application.
Data Layers
Area: | programming \ languages \ java \ \ \ |
Ref: | |
Loc: | |
Tags: | |
|