0

We got the following class signatures:

car:

public class car<E extends Parts> [...] 

parts:

public abstract class parts<E extends Stuff> [...] public class Tire<T extends StoneTire> extends parts<T>[...] 

stuff:

public abstract class Stuff [...] public class Painting extends Parts [...] [...] 

We want to save the car in a Treeset < Parts< E>> (in the "Car"-class), but the compiler says nope :[ Because if we try to save a Tire in a City of Tools he cant find the StoneTire type in the bounds of Tool.

3
  • Where is the M used in your method declared? Commented Jun 15, 2014 at 15:33
  • @SotiriosDelimanolis in the method: public final <M extends Museum<E>> void addMuseum(final M museum) Commented Jun 15, 2014 at 17:25
  • Please show us what toolCity is. Commented Jun 15, 2014 at 18:07

1 Answer 1

2

Your method

public final <M extends Museum<E>> void addMuseum(final M museum) 

has its own type parameter M, but it also depends on the class type parameter E. M is bound at the method invocation, but E is bound at the declaration of the instance (or of the expression).

You've got

toolCity.addMuseum(m1); 

where toolCity seems to be an instance of

public class ToolCity extends City<Tool> // E 

SO the method being invoked, fully bound, is

public final void addMuseum(final Museum<Tool> museum) ... 

But your m1, from the exception message, seems to be a

Museum<StoneTool> m1 = ... 

A Museum<StoneTool> is not a subtype of Museum<Tool> and can therefore not be used as an argument to something that expects the latter.

Sign up to request clarification or add additional context in comments.

2 Comments

toolCity is a new "City<Tool>" instance! "Tool" is an abstract class and "StoneTool" extends "Tool" so its an subtype?!? The method should accept "Museum" and any subtypes of it and any subtype from "Tool"?
@horrorhorst No, for a City<Tool> the method accepts a subtype of Museum<Tool>. Museum<StoneTool> is not a subtype of Museum<Tool>.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.