I have this interface
public interface MyInterface{
Collection<T> Find(T t);
Collection<T> FindAll();
T FindById(int id);
void Add(T t);
void Remove(T t);
}
What must I do for the T FindById(int id) method if I need to be guaranteed that T will have an Id of type int? Should I create another interface that my object must extend to use FindById?
To really get that type-safety, as well as flexibility for non-
intidentifiers, try something like:You can then lock down the typing:
(I’ve fixed your method capitalization to Java-style too 😉