Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28996 > unrolled thread

generic extends problem

Started byPhilipp Kraus <philipp.kraus@flashpixx.de>
First post2014-07-08 08:24 +0200
Last post2014-07-22 14:54 +0200
Articles 3 — 2 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  generic extends problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-08 08:24 +0200
    Re: generic extends problem Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-07-08 08:22 -0400
      Re: generic extends problem Philipp Kraus <philipp.kraus@flashpixx.de> - 2014-07-22 14:54 +0200

#28996 — generic extends problem

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2014-07-08 08:24 +0200
Subjectgeneric extends problem
Message-ID<lpg2q5$2ued$1@ariadne.rz.tu-clausthal.de>
Hello,

I have got a complex class structure, the signature of the class is:

public abstract class IMultiLayer<T extends IStepable & Painter> 
extends CompoundPainter<T> implements IQueue<T>, 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<T> extends Queue<T>


I create classes with

public class myContent implements IStepable, Painter

public class myLayer extends IMultiLayer<myContent>

I can compile the structure with Java 1.8, but I get an 
ClassCastException. I have defined a Map
with

Map<String, ILayer> 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

Thanks

Phil

[toc] | [next] | [standalone]


#29003

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2014-07-08 08:22 -0400
Message-ID<lpgnqe$27q$1@dont-email.me>
In reply to#28996
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<T extends IStepable & Painter> extends
> CompoundPainter<T> implements IQueue<T>, 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<T> extends Queue<T>
>
>
> I create classes with
>
> public class myContent implements IStepable, Painter
>
> public class myLayer extends IMultiLayer<myContent>
>
> I can compile the structure with Java 1.8, but I get an
> ClassCastException. I have defined a Map
> with
>
> Map<String, ILayer> 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 <http://sscce.org/>.

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

[toc] | [prev] | [next] | [standalone]


#29190

FromPhilipp Kraus <philipp.kraus@flashpixx.de>
Date2014-07-22 14:54 +0200
Message-ID<lqlmtg$23bj$1@ariadne.rz.tu-clausthal.de>
In reply to#29003
On 2014-07-08 12:22:29 +0000, Eric Sosman said:

> 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<T extends IStepable & Painter> extends
>> CompoundPainter<T> implements IQueue<T>, 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<T> extends Queue<T>
>> 
>> 
>> I create classes with
>> 
>> public class myContent implements IStepable, Painter
>> 
>> public class myLayer extends IMultiLayer<myContent>
>> 
>> I can compile the structure with Java 1.8, but I get an
>> ClassCastException. I have defined a Map
>> with
>> 
>> Map<String, ILayer> 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 <http://sscce.org/>.

Sorry for the late answer, but the structure was quite right, but my 
cached Java classes
are exists in an older version. I habe removed the cache and recompile 
the whole project
and everything works fine

Phil

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web