I have generic structure and I need to search using various generic type's attributes.
Let's think of following implementation:
public class Person {
private int id;
private String name;
// + getters & setters
}
Now I have my custom data structure and one of it's method is like:
public T search(T data) { ... }
That is nonsense of course. What I really need in code is something like:
Person p = structure.search(12); // person's id
or
Person p = structure.search("Chuck N."); // person's name
So in pseudoJava (:)) the code would be something like this:
public T search(T.field key)
This isn't possible of course :( But how can one deal with this kind of situation? The point is: I don't want to force client's classes (like Person) to implement my own interface or to extend my own class. Is there any workaround?