binary-search;binary-search-tree;custom-set;linked-list;simple-linked-list: use generics?
See original GitHub issuelinked-list
’s tests only insert and expect integers. However, the tests force the practitioner to generify the class.
We should:
- remove type variables from the class signature in the tests and either expect
Number
orInteger
- or expand the test suite to put all kinds of objects in the collection.
What do you think?
Issue Analytics
- State:
- Created 7 years ago
- Comments:22 (21 by maintainers)
Top Results From Across the Web
Java : How do I implement a generic Binary Search Tree?
1) You can get into generics/templates. 2) Have your tree take in a type Object instead of int and have the user be...
Read more >5.3 Generics · Hug61B - joshhug
We want it to take any kind of Map61B , no matter what the actual types for the generics are. However, the following...
Read more >#11.3 Collection and Generics | Generics with List - YouTube
Practical implementation of Generics with ListIn this video we will see ... type - Using Generics - Syntax of creating List with Generics...
Read more >Java Generics Tutorial with Examples - Java Guides
A generic type is a class or interface that is parameterized over types. We use angle brackets (<>) to specify the type parameter....
Read more >Java Generics Examples
Reusable Code, It enables programmers to implement generic algorithms by specifying type parameter in method and class and interfaces and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I did
simple-linked-list
today, and I found the test suite’s handling of generics extremely confusing. Specifically:linked-list
, the class is not explicitly specified as generic in the test suite. My IDE did not make the class generic when auto-creating the class. I only realized generics were necessary when I looked closely at the testscanReturnListAsArray()
(which expects an Integer array) andcanReturnEmptyListAsEmptyArray
(which expects an Object array).asArray()
, which has to return a generic type array to pass the tests. I couldn’t figure out how to convert the values from ints to type T for array returned.I think it would be very helpful to more closely align
simple-linked-list
withlinked-list
and make the class generic up front in the tests. I thought this exercise would be a simpler version of my solution tolinked-list
and was surprised at how much trouble I was having solving it.Please do! Least she forget, she’s made significant contributions in mere suggestions (e.g. more exercises with starter code); great source of ideas!