Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #34455
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-06-03 08:52 -0700 |
| References | <ae727260-8c33-4648-8995-f387a6eb8b52@googlegroups.com> <dr914vFsbd4U1@mid.individual.net> |
| Message-ID | <de7842b3-934b-46d9-bcda-42034e0eabdb@googlegroups.com> (permalink) |
| Subject | Re: How to extend an array |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Wednesday, June 1, 2016 at 5:07:55 PM UTC-4, Robert Klemme wrote:
> After reading the thread it seems you might want parallel inheritance
> hierarchies like this:
I've never used that syntax before. So if we want to implement a second set of extended interfaces like that we just add it into that block, then every reference needs another "?" ?
import java.util.ArrayList;
import java.util.List;
import javax.swing.Icon;
public class TestStatic3 {
public static void main(final String[] args) {
final BaseClass bc = new BaseClass();
bc.addListener(new BaseListener() {
@Override
public void fast(final BaseClass<?, ?> o) {
System.out.println("simple bc");
}
});
final DerivedClass dc = new DerivedClass();
dc.addListener(new DerivedListener() {
@Override
public void fast(final BaseClass<?, ?> o) {
System.out.println("simple dc");
}
@Override
public void superFast(final DerivedClass<?, ?> o) {
System.out.println("more complex dc");
}
});
bc.notifyFast();
dc.notifyFast();
dc.notifySuperFast();
System.out.println("done");
}
public static interface BaseListener {
void fast(final BaseClass<?, ?> o);
}
public static class BaseClass<L extends BaseListener, I extends Icon> {
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);
}
}
}
public static interface DerivedListener extends BaseListener {
void superFast(final DerivedClass<?, ?> o);
}
public static interface CustomIcon extends Icon {
}
public static class DerivedClass<L extends DerivedListener, I extends CustomIcon> extends BaseClass<L, I> {
public void notifySuperFast() {
for (final L listener : getListeners()) {
listener.superFast(this);
}
}
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous 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