what is a generic class???can u provide a simple demo program??
1
Expert's answer
2015-08-13T02:55:20-0400
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)); System.out.println(value1); Integer intValue1 = value1.getValue(); GeneralPrinter<String> value2 = new GeneralPrinter<String>("Hello world"); System.out.println(value2);
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment