I have a problem passing a parameter to a generic method. The code is as follows:
public class View<T extends View<T,PM>, PM extends Source> { protected PM source; protected EventManager<T, PM> eventManager; public View(PM s){ this.source = s; eventManager = new EventManager<T, PM>(); eventManager.setTarget(this);
Eclipse gives me an error that I introduced in the comment on the line "eventManager.setTarget (this);". I cannot understand why this gives me this error. Anyway, I found a solution (apparently), but I'm not sure if I did a “clean” or a “dirty” thing. The solution is this:
eventManager.setTarget((T)this);
but this gives me a warning: “Security type: the checkbox from“ View in T ”is unchecked. To exclude the warning, I also added the following constructor method:
@SuppressWarnings("unchecked")
It seems to work, but what's wrong? Do you have another “cleaner” solution (if one exists)? Do you think this is a dirty approach?
Any colds are very welcome.
source share