How to set own model to an interface which get generic types parameters

This is my interface ,

public interface OnSendEntityMessageListener {
    public <T> void onSendEntity(Class<T> entityType, T message);
}

When i want to use interface like below , i get a build-in error like

The method onSendEntity(Class, T) in the type AFragment.OnSendEntityMessageListener is not applicable for the arguments (Class, String)

private void SendASampleMessageToParent(Account account) {
      mSendEntity.onSendEntity(Account.class, "Fragment Message. : "+ account.getName());
   }

Modal

public class Account {
    String Name;

    public String getName() {
        return Name;
    }

    public void setName(String name) {
        Name = name;
    }
}

Thanks for your helps

Answers


You have defined the parameter message as T in your interface. But the T type argument in your example is already bound to the type Account when you're invoking

mSendEntity.onSendEntity(Account.class, "Fragment Message. : "+ account.getName());

You might have meant to declare your method as

public <T> void onSendEntity(Class<T> entityType, String message);

instead.


Need Your Help

Countdown Timer in a strip status label c#

c# winforms timer countdown

My program has a parameter that starts up the winform and waits x number of seconds before it runs a function. Currently I am using Thread Sleep for x seconds and then the function runs. how can I ...

Return values from a Correlation Matrix in R

r loops matrix return correlation

I have a correlation matrix (called correl)that is 390 x 390 so I would like to scan for values that are within 0.80 &amp; 0.99. I have written the following loop:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.