question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

binary-search;binary-search-tree;custom-set;linked-list;simple-linked-list: use generics?

See original GitHub issue

linked-list’s tests only insert and expect integers. However, the tests force the practitioner to generify the class.

We should:

  1. remove type variables from the class signature in the tests and either expect Number or Integer
  2. or expand the test suite to put all kinds of objects in the collection.

What do you think?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
rstockbridgecommented, May 14, 2017

I did simple-linked-list today, and I found the test suite’s handling of generics extremely confusing. Specifically:

  • Unlike 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 tests canReturnListAsArray() (which expects an Integer array) and canReturnEmptyListAsEmptyArray (which expects an Object array).
  • I tried to proceed with a non-generic class treating the input values as ints, but got tripped up trying to write 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.
  • (Side note: this was in interesting introduction into the difficulties of creating generic arrays in Java!)
  • After consulting @stkent, I made the class generic, and was able to complete the exercise.

I think it would be very helpful to more closely align simple-linked-list with linked-list and make the class generic up front in the tests. I thought this exercise would be a simpler version of my solution to linked-list and was surprised at how much trouble I was having solving it.

1reaction
jtiggercommented, May 5, 2017

[Aside: I’ve been trying to encourage Rebecca to post issues here rather than telling me when she thinks an exercise is awkwardly placed… no luck yet, but I’ll keep asking her!]

Please do! Least she forget, she’s made significant contributions in mere suggestions (e.g. more exercises with starter code); great source of ideas!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found