Find the best solutions to your questions at Westonci.ca, the premier Q&A platform with a community of knowledgeable experts. Experience the convenience of getting reliable answers to your questions from a vast network of knowledgeable experts. Get detailed and accurate answers to your questions from a dedicated community of experts on our Q&A platform.

How to create a comparator generic type in java.

Sagot :

Answer:

public class Person {

//fields

private int id;

private String name;

private Payment pay;

//constructor

public Person(String name, int id,

int startSal, int startBon){

this.name = name;

this.id = id;

this.pay = new Payment(startSal, startBon);

}

//method get name

public String getName(){

return name;

}

//method get id

public int getId(){

return id;

}

//method get start salary

public int getStartSalary(){

return pay.startSalary;

}

//method get start bonus

public int getStartBonus(){

return pay.startBonus;

}

//inner payment class

private class Payment{

int startSalary;

int startBonus;

public Payment(int sal, int bon){

this.startSalary = sal;

this.startBonus = bon;