KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have couple of thoughts regarding the following: public interface MaxStack<T extends Comparable <T>> 1-Why does the class that implements MaxStack should be written like this: public class MaxStackclass<T extends Comparable <T>> implements MaxStack<T> and not public class MaxStackclass<T extends Comparable <T>> implements MaxStack<T extends Comparable <T>> ? 2- why do the private variables of this class, when I use generics, should be written only with <T> and not with <T extnds Comparable<T>> ? For example, private List<T> stack= new ArrayList<T>(); 3-What is the difference between <T extends Comparable<T>> and <T extends Comparable> - if I need to compare bewteen elements in my class, both will be O.K, no? Edit: I think that thee problem with 3 is that maybe it allows to insert of a list that was defined in the second way to have different elements which all extends from comparable and then when I want to compare them, it won't be possible, since we can't compare String to Integer, both extend from Comparable.
Tags (comma-separated)
Save Edits
Cancel