Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34437

Re: How to extend an array

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: How to extend an array
Date 2016-06-01 23:07 +0200
Message-ID <dr914vFsbd4U1@mid.individual.net> (permalink)
References <ae727260-8c33-4648-8995-f387a6eb8b52@googlegroups.com>

Show all headers | View raw


On 31.05.2016 16:52, Eric Douglas wrote:
> This looks funny but seems to work.  Does it make sense, is there
> better syntax, or anything I'm missing?

First of all: the title is totally misleading.  This is not about 
arrays, it's about ArrayLists - even about generic collections generally.


After reading the thread it seems you might want parallel inheritance 
hierarchies like this:

package listeners;

public interface BaseListener {
   void fast(final BaseClass<?> o);
}

package listeners;

import java.util.ArrayList;
import java.util.List;

public class BaseClass<L extends BaseListener> {
   private final List<L> listeners = new ArrayList<>();

   protected List<L> getListeners() {
     return listeners;
   }

   public void addListener(final L listener) {
     getListeners().add(listener);
   }

   public void notifyFast() {
     for (final L listener : getListeners()) {
       listener.fast(this);
     }
   }
}

package listeners;

public interface DerivedListener extends BaseListener {
   void superFast(final DerivedClass<?> o);
}

package listeners;

public class DerivedClass<L extends DerivedListener>
extends BaseClass<L> {

   public void notifySuperFast() {
     for (final L listener : getListeners()) {
       listener.superFast(this);
     }
   }
}

Is this what you had in mind?

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 07:52 -0700
  Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 11:52 -0400
    Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 11:56 -0400
      Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 09:19 -0700
        Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 14:01 -0400
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 09:09 -0700
      Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 14:11 -0400
        Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-05-31 11:25 -0700
          Re: How to extend an array Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-05-31 17:01 -0400
            Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-01 04:57 -0700
  Re: How to extend an array Roedy Green <inquiry@mindprod.com> - 2016-05-31 21:56 -0700
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-01 04:49 -0700
  Re: How to extend an array Robert Klemme <shortcutter@googlemail.com> - 2016-06-01 23:07 +0200
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-03 05:38 -0700
      Re: How to extend an array Robert Klemme <shortcutter@googlemail.com> - 2016-06-04 19:17 +0200
    Re: How to extend an array Eric Douglas <e.d.programmer@gmail.com> - 2016-06-03 08:52 -0700

csiph-web