Passing Interface Class as a Parameter in Java

interface, java

Solution

Perhaps you need

public void sendNotification( Class<? extends IMech> mechanism ) { 

Problem

I have an interface: ``` public interface IMech { } ``` and a class that implements it ``` public class Email implements IMech { } ``` and a third class that has this method implemented: ``` public void sendNotification( Class< IMech > mechanism ){ } ``` now I'm trying to call that method like so ``` foo.sendNotification(Email.class); ``` but i keep getting an exception saying: ``` The method sendNotification(Class<IMech>) in the type RemediationOperator is not applicable for the arguments (Class<Email>) ``` Shouldn't this work if it interfaces that class?

Original source