Can the contains() method from the Vector class in Java be manipulated from another class (without expanding the Vector class)?
Let's say we have this:
class AuxType {
String name;
int type;
AuxType(String name, int type) {
this.name = name;
this.type = type;
}
}
class Main {
void aMethod() {
Vector<AuxType> v = new Vector<AuxType>();
v.add(new AuxType("a", 1));
v.add(new AuxType("b", 2));
v.add(new AuxType("c", 3));
for (int i = 0; i < v.size(); i++) {
if (v.get(i).type == 2) {
System.out.println("Found it!");
}
}
}
}
The for/if lines could be written as
if (v.contains(2)) {
//
}
Is a way through which I can change how contains() works (either in the AuxType class or in the aMethod() function from Main)?
EDIT: NOT A DUPLICATE
I wasn't asking about calling a method from a class, but about changing it without extending that class.