0

java.util.Vector has methods: remove(int index) and remove(Object o)

I have:

vector<Integer> a;
int b=3;

I want:

Invoke method remove(Object o) with b variable. Writing a.remove(b) obviously invokes remove(int index)

Thanks in advance, Maciej

Vistritium
  • 380
  • 2
  • 12
  • possible duplicate of [Properly removing an Integer from a List](http://stackoverflow.com/questions/4534146/properly-removing-an-integer-from-a-listinteger) – assylias Mar 14 '13 at 18:39
  • `a.remove((Integer) 3);` or `a.remove((Integer) b);`. – assylias Mar 14 '13 at 18:43

1 Answers1

4
a.remove(Integer.valueOf(b)); 

Should work. An Integer will be resolved as a reference type first, and match remove(Object), before autoboxing is considered to call remove(int).

From the Java Language Spec, 15.2.2:

Compile-Time Step 2: Determine Method Signature

The first phase (§15.12.2.2) performs overload resolution without permitting boxing or unboxing conversion, or the use of variable arity method invocation. If no applicable method is found during this phase then processing continues to the second phase.

The second phase (§15.12.2.3) performs overload resolution while allowing boxing and unboxing...

Mark Peters
  • 80,126
  • 17
  • 159
  • 190
  • Wow, thanks. This may not explain how to invoke overloaded method with less specific argument but solves my problem :) – Vistritium Mar 14 '13 at 18:46