Java: I have implemented my own version of a Binary Heap
. It should be able to store any type of Comparable object. The objects that are inserted into the heap come from input data, and all the input data will be of the same type. Is there a way to tell what Object type a given input is? I'm using
BufferedReader in = new BufferedReader(new InputStreamReader(System.in))
to read the inputs, and in.readLine()
always returns a String. Right now, I'm explicitly testing to see if the user inputs an Integer, otherwise the object is always stored as a String.
What is the best way to read an input, see what type it is and then create a BinaryHeap<T>
of that type, to then insert properly?