[concurrency-interest] subList, subMap and navigable

Rabea Gransberger rgransberger at gmx.de
Tue Jul 24 13:37:05 EDT 2012

Am 23.07.2012 21:16, schrieb Stanimir Simeonoff:
> Imagine the case
> SomeInterface{
>    void process(java.util.List)
> }
> If the code is invoked locally it just works and not copy but supplying
> the view is potentially more performance friendly.

A SerializableList interface would help at this point to explicitly only 
allow Lists which are Serializable and making it clear which objects can 
be passed in and handled as expected.

But as there is no such interface, creating a new interface and 
object/proxy might not be worth it and does not really make a difference 
to your approach with ObjectOutputStream.replaceObject.

public interface SerializableList<E> extends Serializable, List<E> {
  public static class Factory {
   private Factory() {

   public static <E> SerializableList<E> create(List<E> list) {
    if (Serializable.class.isInstance(list)) {
     return createProxy(list);
    } else {
     return createProxy(new ArrayList<E>(list));

   @SuppressWarnings("unchecked") private static <E> SerializableList<E> 
createProxy(List<E> list) {
    return (SerializableList<E>) 
Proxy.newProxyInstance(Factory.class.getClassLoader(), new Class[] 
{Serializable.class, List.class, SerializableList.class}, new 

  public static class SerializableListProxy implements InvocationHandler {

   private final List<?> delegate;

   public SerializableListProxy(List<?> delegate) {
    this.delegate = delegate;

   @Override public Object invoke(Object proxy, Method method, Object[] 
args) throws Throwable {
    return method.invoke(this.delegate, args);

More information about the Concurrency-interest mailing list