title: Implementing a new LinkedList method in Java
body: <p>I have an assignment that involves creating three methods that manipulate a linked list.  The instructions dictate that I use the following constructor:</p>
  
  <pre><code> public MyList (LinkedList&lt;Integer&gt; list) {
   ...
   }
  </code></pre>
  
  <p>However, Eclipse seems to not like my code regardless of how I try integrate it.  Here's my current attempt:</p>
  
  <pre><code>import java.util.*;
  
  public class ListClass {
  
  public static void main(String[] args) {
      LinkedList&lt;Integer&gt; list = new LinkedList&lt;Integer&gt;();
      list.add(10);
      list = MyList(list);
  }
  
  public MyList (LinkedList&lt;Integer&gt; list){
      LinkedList&lt;Integer&gt; r = list;
      return r;
  }
  }
  </code></pre>
  
  <p>Now I thought that the MyList constructor above would happily just return the list entered, but my Java skills are really weak.  I've been going through the tutorials and gave this a go, but it hasn't worked as I thought it would.</p>
  
  <p>Anyway so Eclipse is giving me two errors - at the "list = MyLIst(list);" line it says the method MyList is undefined for ListClass, and at the "public MyList" line it says "the return type for the method is missing" - but I've told it that r is a linked list, and to return that.</p>
  
  <p>This hurts my brain and I can't manage to figure it out, can anyone give me a hand?  I think if I were able to get the above code working, I should be able to get the rest sorted.</p>
  
  <p><strong>Newer code</strong></p>
  
  <p>As rightfully pointed out, my class name isn't the same as my supposed constructor name.  So here's the adjusted code:</p>
  
  <pre><code>import java.util.LinkedList;
  
  public class MyList {
  
  public static void main(String[] args) {
      LinkedList&lt;Integer&gt; list = new LinkedList&lt;Integer&gt;();
      list.add(10);
      list.add(-20);
      MyList(list);
  }
  
  public MyList(LinkedList&lt;Integer&gt; list) {
      LinkedList&lt;Integer&gt; newList = list;
      System.out.println(newList);    
  }
  }
  </code></pre>
  
  <p>This has solved the "return type" error (thank you), though I'm still getting the "undefined" error.</p>