Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Queue and Map interface Date: Fri, 13 Jun 2014 17:32:20 -0400 Organization: A noiseless patient Spider Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 13 Jun 2014 21:32:25 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="18170"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9MgGKRwbSe1Xr/8jKObtT" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Cancel-Lock: sha1:ero/NB7QqnPJ5E8FlSQIxPsXeIE= Xref: csiph.com comp.lang.java.programmer:28724 On 6/13/2014 4:52 PM, Philipp Kraus wrote: > Hello, > > I would like to create a class which implements a Map and a Queue with > > class myMapQueue extends myAbstractClass implements Map, > Queue {} > > The problem is the remove(Object) method, because the method is defined > in the Queue and the Map > interface in the Queue with boolean remove(Object) and in the Map with V > remove(Object), so I get > a "clash error". How can I solve this problem. "Favor composition over inheritance." -- Bloch In short, I don't believe you can do what you want -- not in the way you want to do it. An alternative might be to implement Map in an outer class, one that also contains a Queue implementation as an inner class. The outer class would also have a getQueue() method to return an instance of the inner class -- whether that's a new instance created on the fly or a single instance that's created once per outer class is up to you. For even more "favoritism," you could have the outer class implement neither Map nor Queue, and delegate both those interfaces to inner classes. -- Eric Sosman esosman@comcast-dot-net.invalid