posted Mar 16, 2015, 7:50 AM by Samuel Konstantinovich   [ updated Mar 16, 2015, 9:05 AM ]
GOAL: Generic conversion of code

Before it is too late:
-Make sure your MyLinkedList.java includes the name() method. ( non-static, "last.first" )
-Devise a set of test conditions to determine if your linked list behaves properly. You may wish to use an ArrayList<> to compare the operations to.

1. We want to replace LNode with LNode<T>.
2. We want to replace all value types (in this case int) with T.
3. We need to do step 1 for ALL cases (EXCEPT THE CONSTRUCTOR!), not just the class header, otherwise it will think we want a default'Object' LNode. 
4. We should compile "javac file.java -Xlint:unchecked" to find and fix all warnings. This is easy enough for a simple generic like this data structure. (This whole process is more complicated when using a generic interface, and not required for the class.)

public class LNode{
private int data;
private LNode next;

public LNode(int data){

public void setNext(LNode n){
next = n;
public void setData(int d){
data = d;
public int getData(){
return data;
public LNode getNext(){
return next;