First of all, here is the full error (which is specific to MathSubset not getting a proper parameter): Bound mismatch: The type S is not a valid substitute for the bounded parameter > of the type QifFixer. MathSubset.
Up vote 1 down vote favorite share g+ share fb share tw.
I am writing some classes using Generics but I can't find a solution for the class SolutionsSubset and so I a getting the error "type parameter S is not within its bound". I have read previous questions about the same error but I can't solve it for my case. Could anybody help me to improve my knowledge about generics?
Any reference to a good book (I can find in google a lot of information but if someone can reccommend a book, tutorial, etc. will be welcome). Although I tried to keep in mind the rules to ask a question but I apologize if my question doesn't fulfill these rules. I have the following classes and interfaces: public interface Subset> extends Comparable> public class MathSubset> extends TreeSet implements Subset public interface Solution> public interface Solutions> extends Iterable public class SolutionsSubset> extends MathSubset implements Solutions I need that Subset extends Comparable.
In SolutionsSubset, the class MathSubset stores Solution objects. How do I have to change these definition to make it work? Thanks you in advance java generics syntax-error bound link|improve this question asked Dec 12 '10 at 17:51user53969462.
First of all, here is the full error (which is specific to MathSubset not getting a proper parameter): Bound mismatch: The type S is not a valid substitute for the bounded parameter > of the type QifFixer. MathSubset The problem is that MathSubset expects a , but you're giving it a S extends Solution - those types having nothing to do with each other, because a Solution does not inherit or implement Comparable. If anything, you could try this: public class SolutionsSubset> extends MathSubset implements Solutions>; Unfortunately, this will STILL not work because MathSubset implements Iterable, but so does Solutions.
An easy fix would be for Solutions to not extend Iterable, but it really sounds to me like you're trying to use a more complex approach than you need to. May be a "has-a" instead of "is-a" design might be more beneficial here?
Thank you for your help; I finally decided to change to a "has-a" design. Anyway, your solution helped me to understand in a better way Generics in Java – user539694 Dec 14 '10 at 15:10.
Generics are something that can quickly get out of hand, especially if you try to "be all generic" all at once. Less is more. What always helps me is to start concrete (including the implementation) and then slowly substitute generic parameters in, one parameter and class at a time.
Could anybody help me to improve my knowledge about generics? angelikalanger.com/GenericsFAQ/JavaGener... Not a tutorial, but lots of useful info. Its one of those references that you read the parts you can understand, but come back to over and over again in the future as you gain more mastery and more of it begins to make sense.
Thank you very much. It is a very good web about Java and Generics. – user539694 Dec 14 '10 at 15:07.
In order to be used as the type argument in MathSubset, SolutionsSubsets S must extend Comparable. As a compilable example: import java.util. TreeSet; interface Subset> extends Comparable> { } class MathSubset> extends TreeSet implements Subset { public int compareTo(Subset other) { throw new Error(); } } interface Solution> { } interface Solutions> extends Iterable { } class SolutionsSubset & Comparable> extends MathSubset implements Solutions { } A few comments: This is very abstract example, and so not easy to think about.
Laying out the code so you don't need to scroll is good. There's an awful lot of inheritance going on here, perhaps compose rather than, say, extending TreeSet. It's difficult to distinguish between the identifiers Solutions and Solution.
Thanks. Your solution was interesting although I finally changes the design to make it simpler. – user539694 Dec 14 '10 at 15:14.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.