I'm wondering if is possible pass types by argument in Java.
Let me explain better:
Suppose the next code
class Bee {
// Class implementation
}
class Worker extends Bee {
// Class implementation
}
class Queen extends Bee {
// Class implementation
}
And now create a container with my bees objects
Vector<Bee> x=new Vector<Bee>();
// ...
for(i=0;i<10;i++)
x.add(new Worker());
// ...
for(i=0;i<10;i++)
x.add(new Queen());
Now I want create a generic method that iterates the vector and returns a set with a specific type of bees, Worker or Queen. How to do this?
EDIT
I tried
search(x,Worker.class);
static public <T extends Bee> Set<T> search(List<Bee> bees, Class<T> clazz){
// ...
}
and I got an error reporting "The method search(List, Class) is no applicable for the arguments (Set, Class)". The problem is on 2nd argument because the types are incompatible.