public class Customer{ private T id; public void setId(T id) { this.id = id; } public T getId() { return id; } } // Usage Customer customer = new Customer<>(); customer.setId("1234");
import java.util.UUID; public class ProductIn this example, a Product object of type T is defined with an ID of type Integer. The setId method is called for the product object to set the ID to a unique value. The generateId method is called to generate a unique ID using the UUID Java library. Package library: java.util{ private T id; public void setId(T id) { this.id = id; } public T getId() { return id; } // Generate a unique ID for the product public void generateId() { this.id = (T) UUID.randomUUID(); } } // Usage Product product = new Product<>(); product.generateId(); // Generates a unique ID for the product