Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34437
| Path | csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Robert Klemme <shortcutter@googlemail.com> |
| 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 | <dr914vFsbd4U1@mid.individual.net> (permalink) |
| References | <ae727260-8c33-4648-8995-f387a6eb8b52@googlegroups.com> |
| 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 | <ae727260-8c33-4648-8995-f387a6eb8b52@googlegroups.com> |
| Xref | csiph.com comp.lang.java.programmer:34437 |
Show key headers only | 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
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