What does this class declaration mean in Java?
I just study trees and one thing I don't understand is class declarations:
For example: class binarysearchtree < T extensions comparable
Now, please explain the contents in brackets and ""?
Can you quote any of my good sources? thank you.
Solution
This declares a class with a single generic type parameter Because for a binary search tree, it must compare two items, which needs to be specified so that the compiler can validate it
The part in angle brackets is the type parameter T and its constraints, which indicates:
>No matter what t is, it should extend comparable (< T extends comparable <... > >). > The comparator should be able to compare itself with T or super class T ()
Because t can usually be anything, it limits the choice of types that make sense to implement the search tree