Will Jones wrote:How can accomplish what I'm trying to do?
Will Jones wrote:But in my case I am talking about an interface, not a super class. An Object is a super class of a String, but an interface (such as IMyClass or List<String>) that my class (such as MyClass or ArrayList<String>) implements is not a super class...
Will Jones wrote:By doing this I was hoping to generalize my presenter references so that if the view were to ever change the presenter layer could essentially remain as is.
Will Jones wrote:
In your Oracle generics tutorial example you explained that you can't cast a String to an Object and then expect to use it like an Integer because a String... just isn't an Object. That makes sense to me. But in my case I am talking about an interface, not a super class. An Object is a super class of a String, but an interface (such as IMyClass or List<String>) that my class (such as MyClass or ArrayList<String>) implements is not a super class, and as I demonstrated with the code snipped using "b = a;" we see that we can in fact safely cast in that situation (from an implementer of an interface to an object with the same type as that interface). But the moment I take the exact same example and make them parameters in a class with a parameterized type such as List<T> I get the casting error. That was what was confusing me. If, in my original example, I can cast "b = a;" safely then why can't I cast "y = x;" ? What is the difference? How could I remedy it?
Will Jones wrote:So actually using Paul's solution... this is what could be done...
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton