Hi all,
I was solving the mock
test from Khalid Mughal and came across this question
Which type constraints, when inserted at (1), will allow the class to compile?
Select the four correct answers.
(a) N extends Object
(b) N extends Comparable<N>
(c) N extends Object & Comparable<N>
(d) N extends Number
(e) N extends Number & Comparable<N>
(f) N extends Comparable<N> & Number
(g) N extends Integer
(h) N extends Integer & Comparable<N>
Ans: (b),(c),(e) and (g).
I did not come across a combination generic type like this before and just wanted to know if there are any rules in how to define such generic types.
For example can we say <N> Number<N> & Comparable<N> instead of N extends Number & Comparable<N> ?
Please explain the specifics of this kind of implementation.
Thanks,
Kakani