### Question:
ReferenceListeners implements JListeners<L> { @Nonnull @Override public <LE extends L> List<LE> getListenersOfType(@Nonnull Class<LE> type) { final List<L> listeners = getListeners(); final List<LE> result = new ArrayList<LE>(listeners.size()); for (L listener : listeners) { if (type.isAssignableFrom(listener.getClass())) { result.add((LE) listener); } } return result; } private  ReferenceListeners(@Nonnull ReferenceProducer<R, L> referenceProducer); @Nonnull static ReferenceListeners<R, L> newInstance(@Nonnull ReferenceProducer<R, L> referenceProducer); @Nonnull static ReferenceListeners<WeakReference<L>, L> newWeakReferenceInstance(); @Nonnull static ReferenceListeners<WeakReference<L>, L> newHardReferenceInstance(); @Override boolean addListener(@Nonnull final L listener); @Override boolean removeListener(@Nonnull final L listener); @Override void removeListeners(); @Override @Nonnull List<L> getListeners(); @Nonnull @Override List<LE> getListenersOfType(@Nonnull Class<LE> type);  }### Answer:
@Test public void testGetListenersOfType() throws Exception { final JListeners<TestListener> listeners = ReferenceListeners.newHardReferenceInstance(); final TestListener l1 = new TestListener1(); final TestListener l2 = new TestListener2(); final TestListener l3 = new TestListener3(); Assert.assertTrue(listeners.addListener(l1)); Assert.assertTrue(listeners.addListener(l2)); Assert.assertTrue(listeners.addListener(l3)); final Collection<TestListener> testListeners = listeners.getListenersOfType(TestListener.class); Assert.assertEquals(3, testListeners.size()); final Collection<TestListener1> testListeners1 = listeners.getListenersOfType(TestListener1.class); Assert.assertEquals(1, testListeners1.size()); final Collection<TestListener2> testListeners2 = listeners.getListenersOfType(TestListener2.class); Assert.assertEquals(2, testListeners2.size()); final Collection<TestListener3> testListeners3 = listeners.getListenersOfType(TestListener3.class); Assert.assertEquals(1, testListeners3.size()); }