title: Java can not find methods like addFirst or addLast
body: <pre><code>import java.util.List;
  import java.util.LinkedList;
  class Test {
      public static void main(String[] args) {
          List&lt;String&gt; list = new LinkedList&lt;String&gt;();
          list.addLast("string");
          list.removeLast();
      }
  }
  </code></pre>
  
  <p>When I compile the code:</p>
  
  <pre><code>$ javac Test.java
  Test.java:6: error: cannot find symbol
          list.addLast("string");
              ^
    symbol:   method addLast(String)
    location: variable list of type List&lt;String&gt;
  Test.java:7: error: cannot find symbol
          list.removeLast();
              ^
    symbol:   method removeLast()
    location: variable list of type List&lt;String&gt;
  2 errors
  </code></pre>
  
  <p>If I instantiate a LinkedList with LinkedList on both sides, then there will be no errors. I have learned that putting List on the left side is better. Why did this happen?</p>
  
  <p>Update #1
  If the variable <code>list</code> is of type <code>List</code>, why does the following code print <code>true</code>:</p>
  
  <pre><code>class Test {
      public static void main(String[] args) {
         List&lt;String&gt; list = new LinkedList&lt;String&gt;();
         System.out.println(list instanceof LinkedList);
      }
  }
  </code></pre>
  
  <p>What I interpret from the result of the above code is that <code>list</code> is an instance of <code>LinkedList</code>. If it's an instance of <code>LinkedList</code>, why can't it call methods declared and defined in <code>LinkedList</code>?</p>
  
  <p>Update #2
  There is <code>forEach</code> method in <code>ArrayList</code> but not in <code>List</code>. Why am I still be able to call <code>forEach</code> method on the <code>list</code> variable after I do</p>
  
  <pre><code>List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>Does this have something to do with lambda expression?</p>