I'm studying Java and would like to know if it's possible to transform the two constructors below in a single constructor but using something like generics or something similar.
public CustomPage(User userInput) {
List<User> user = new ArrayList<User>();
user.add(userInput);
this.content = (List<T>) user;
this.totalElements = (long) 1;
this.totalPages = 1;
this.pageSize = 1;
this.pageNumber = 1;
this.timestamp = new Date().toInstant().toString();
}
public CustomPage(Person personInput) {
List<Person> person = new ArrayList<Person>();
person.add(personInput);
this.content = (List<T>) person;
this.totalElements = (long) 1;
this.totalPages = 1;
this.pageSize = 1;
this.pageNumber = 1;
this.timestamp = new Date().toInstant().toString();
}