N-ary Generic Tree -- Java Interview -
Please forgive me if this question has already been asked. I recently took an interview for a job after completing a code evaluation that was based on the use of N-Arya tree and amp; Two traversal methods
As most examples of this site, I have used generics to define my tree / node data type so that I can apply strict use of any type of data type , Which I declare with tree type. Okay, to reduce a long story, my results were fine but the interviewer asked me why I used generics for my tree data structure, because I told them it is because of any kind of use in my evaluation The best way to implement the data type of the tree was. I also told them that I have created a similar data structure before, and recalled how it implemented it.
Is my first question far?
:
The code using generics has many advantages over non-normal code Is:
- Check on strong compile time. A Java compiler applies normal code to a strong type of probe and issues errors if code violates security of type, fixing runtime errors, it is easy to fix compile-time errors, which are difficult to find It is possible.
- Elimination of cast.
Generic without requiring the following code snippet:
list list = new arrelist (); list.add ("hello"); String s = (string) list.get (0);
The code does not require casting when rewritten to use generics:
list & lt; String & gt; List = New Arrestist & lt; String & gt; (); List.add ("hello"); String s = list.get (0); // No cast
- Enabling programmers to apply normal algorithms Using generic, programmers can apply generic algorithms that work on different types of archives , They can be customized, and those types are safe and easy to read.
Now, you can compare your answer with one of the best answers (if not best).
- Enabling programmers to apply normal algorithms Using generic, programmers can apply generic algorithms that work on different types of archives , They can be customized, and those types are safe and easy to read.
Comments
Post a Comment