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: generic extends problem Date: Tue, 08 Jul 2014 08:22:29 -0400 Organization: A noiseless patient Spider Lines: 53 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 8 Jul 2014 12:22:38 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="2298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KxEpyq3+ZtqFaZf5hJq7u" 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:9jYnOnPoyFXrnF43NADsynw4uXw= Xref: csiph.com comp.lang.java.programmer:29003 On 7/8/2014 2:24 AM, Philipp Kraus wrote: > Hello, > > I have got a complex class structure, the signature of the class is: > > public abstract class IMultiLayer extends > CompoundPainter implements IQueue, IViewableLayer, IDataLayer, > IVoidStepable, ILayer > > The interfaces are defined like > > interface IDataLayer; > interface IStepable; > interface IViewableLayer; > > interface IVoidStepable extends IStepable; > interface IReturnStepable extends IStepable; > interface ILayer extends IStepable; > interface IQueue extends Queue > > > I create classes with > > public class myContent implements IStepable, Painter > > public class myLayer extends IMultiLayer > > I can compile the structure with Java 1.8, but I get an > ClassCastException. I have defined a Map > with > > Map x = new Map(); > x.put( "test", new myLayer ) > (myLayer) x.get("test"); // the exception is raised on the cast > > The message text of the exception is: cannot be cast to IStepable. > I don't understand way the exception is thrown, because the class > implements the correct interface. > If I swap T extends IStepable & Painter to T extends Painter & > IStepable, I get the same exception with > cannot be cast to Painter > > I'm a little bite clueless and need a hint to solve the problem Could you post some actual code, instead of paraphrasing? What you've shown cannot possibly be what you're actually running ("new Map()", "new myLayer" with no parens, ...) See . -- Eric Sosman esosman@comcast-dot-net.invalid