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: Sat, 4 Jun 2016 19:17:44 +0200 Lines: 43 Message-ID: References: <38f6b479-51a0-4bc3-b1f7-f05d3d229f53@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net UzGSsjLCA7twUos2bFd/RgW+u6gPl/B1kfIm3aj8H94p0bBEI= Cancel-Lock: sha1:Bog/JRYLpZ7iT1w1mURh1rsKSMY= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: <38f6b479-51a0-4bc3-b1f7-f05d3d229f53@googlegroups.com> Xref: csiph.com comp.lang.java.programmer:34462 On 03.06.2016 14:38, Eric Douglas wrote: > On Wednesday, June 1, 2016 at 5:07:55 PM UTC-4, Robert Klemme wrote: >> Is this what you had in mind? > I modified your sample into a runnable static class. It appears that > would work, to put the listeners for both classes into a single > array, with some slight confusion to avoid. You omitted the generic declarations which defies the whole point of using them. You should have noticed by the warnings that you should be getting. > I think the way I wrote it may have more overhead but avoids those > issues, should get a compile error if you try to add the extended > listener to the base class instance, Why? Because the "extended listener" extends the base listener. And it is completely logical that you do _not_ get a compile error. > and should work fine only > executing base listener events if you add the base listener to the > extended class instance. You cannot do that because a BaseListener does not extend DerivedListener. The compiler will prevent this. > I don't think those issues should ever come up, normally we'll only > want a base listener for a base class instance and a derived listener > for an extended class instance, but a lot of problems do come up in > programming when an API allows someone to do something they should > never do. (thorough documentation emphasizing what not to do helps?) I think you still have not grasped it fully how this works. I am not even sure what you are trying to achieve. Can you describe that in plain English? Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/