76 285
Assignments Done
Successfully Done
In May 2019

Answer to Question #54078 in Java | JSP | JSF for shashi

Question #54078
what is a generic class???can u provide a simple demo program??
Expert's answer
A class is generic if it declares one or more type variables. These type variables are known as the type parameters of the class. (According to Java Language Specification)
Example of generic class GeneralPrinter with parameter <T>:
class GeneralPrinter<T> {
private T val;

public GeneralPrinter(T arg) {
val = arg;

public String toString() {
return "{" + val + "}";

public T getValue() {
return val;

public class Test {
public static void main(String[] args) {
GeneralPrinter<Integer> value1 = new GeneralPrinter<Integer>(new Integer(10));
Integer intValue1 = value1.getValue();
GeneralPrinter<String> value2 = new GeneralPrinter<String>("Hello world");


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions