0

I'm trying to understand the behavior of Java generics when it comes to assigning a concrete class to an interface type. I have a scenario involving a HashMap where I want to assign instances of a concrete class to an interface type. Here's the relevant code:

public interface iPara
{
  // Interface methods here
}

public class Para implements iPara
{
  // implementation here
}

public interface iBehaviour {
    public void setParameter(Map<String, iPara> parameterlist);
}

public class Behaviour implements iBehaviour {
    public void setParameter(Map<String, Para> parameterlist){
        // Implementation here
    }
}

Unfortunately I got an error

"Name clash: The method setParameter(Map<String,Para>) of type Behaviour has the same erasure as setParameter(Map<String,iPara>) of type iBehaviour but does not override it"

I'd appreciate any insights and explanations that could help me grasp this concept better. Thanks in advance!

Fitri Halim
  • 584
  • 4
  • 11

0 Answers0