Easy learning with example program codes

Generics method example with two parameters


 * This class is used to show the use of 
 * generics method with two parameters.
 * @author codesjava
class Test {
  //Generics method with two parameters.	
  public <T, U> void showItemDetails(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.showItemDetails("Test String.", 100);


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: Generics constructor example.
Previous Topic: Generics method example.


Please follow and like us:

Copyright © 2020 CodesJava Protection Status