Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: How to extend an array Date: Wed, 1 Jun 2016 23:07:41 +0200 Lines: 67 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net b/EqNphH9OY1t2c6GRC+KARPZTynjyScchs4CEO/E6xcMGVjA= Cancel-Lock: sha1:f4MIhABWomjqK8BZ3j/pYsVefsU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:34437 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 { private final List listeners = new ArrayList<>(); protected List 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 extends BaseClass { 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/