CodesJava

Easy learning with example program codes

Generics constructor example with two parameters

Generics constructor example with two parameters:

GenericsTest.java

/**
 * This class is used to show the use of 
 * generics constructor with two parameters.
 * @author codesjava
 */
class Test {
	//Generics constructor with two parameters.
	public <T, U> Test(T itemT, U itemU){
		 System.out.println("Value of the itemT: " + itemT);
		 System.out.println("Type of the itemT: " 
				 + itemT.getClass().getName());
		 System.out.println("Value of the itemU: " + itemU);
		 System.out.println("Type of the itemU: " 
				 + itemU.getClass().getName());
	}
}
 
public class GenericsTest {	
	public static void main(String args[]){
		//String type test
		Test test = new Test("Test String.", 100);
	}
}

Output:

Value of the itemT: Test String.
Type of the itemT: java.lang.String
Value of the itemU: 100
Type of the itemU: java.lang.Integer

Download this example.
 
Next Topic: JUnit Tutorial with example.
Previous Topic: Generics constructor example.

 

Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status