generics - The syntax <T extends Class> in Java -
I have some ideas about the following:
Public Interface Maxstack & lt; T comparative & lt; T & gt; & Gt; The 1-class which applies MaxStacks should be written in such a way: Public class MaxStack class & lt; T comparative & lt; T & gt; & Gt; Maxstacks & lt; T & gt; Applies No more Public class MaxStack class & lt; T comparison & lt; T & gt; & Gt; Maxstacks & lt; T applies and comparative & lt; T & gt; & Gt; ? 2- Why do the personal variables in this class, when I use generic, only and & lt; T extends comparative & lt; T & gt; & Gt; Not with ? For example, Private list & lt; T & gt; & lt; What is the difference between T and comparative & lt; T & gt; & Gt; and and lieutenant ; T is comparative and expanded; - If I need to compare the twentieth element in my class, then both will be fine, will not it? EDIT: I think that the problem with 3 is that maybe it's a list that is defined in different ways of different elements, all of which are spread by being comparable And then when I want to compare them, it will not be possible, because we can not compare the string to the integer, both comparative.
-
In the declaration maximum stack class & lt; T comparison & lt; T & gt; ; & Gt; If you have already expressed limitations on T , then you do not have to do it again. -
There is no need to specify the limit again on the same type parameter as the same reason.
-
& lt; T comparison & lt; T & gt; & Gt; means that T should implement the comparative interface, which can compare two T examples while & Lt; T Comparable & gt; implies T implies comparative so that it can compare two objects s in general, more specific in the past is. If I need to compare twenty elements in my class, then both are OK, no?
OK, technically you can get the same result using both but the declaration & lt; Comparison for T & gt; is expanded, this will include unnecessary clutter, which means that you can use the safe type & lt; Avoid using T and comparing & lt; T & gt;
Comments
Post a Comment