Welcome to Westonci.ca, your one-stop destination for finding answers to all your questions. Join our expert community now! Join our platform to connect with experts ready to provide precise answers to your questions in different areas. Discover detailed answers to your questions from a wide network of experts on our comprehensive 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;