Synchronized in Vector

J

Jun

I noticed that not all the public methods are synchronized.
Some of them are even "setters" like

public boolean remove(Object o) {
return removeElement(o);
}

public void add(int index, Object element) {
insertElementAt(element, index);
}

while

public synchronized Object remove(int index) {
...
}

is syn.

Why?

thanks
 
J

Jon Skeet

Jun said:
I noticed that not all the public methods are synchronized.
Some of them are even "setters" like

public boolean remove(Object o) {
return removeElement(o);
}

public void add(int index, Object element) {
insertElementAt(element, index);
}

while

public synchronized Object remove(int index) {
..
}

is syn.

Why?

What's the point in a method being synchronized if it does nothing but
call precisely one other method which *is* synchronized?
 
T

Tor Iver Wilhelmsen

public boolean remove(Object o) {
return removeElement(o);
}

public void add(int index, Object element) {
insertElementAt(element, index);
}

These are part of the "retrofitted" List API, and they in turn
delegate to the old, synchronized methods.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top