title: Stack class in java.util a violation of Liskov substitution principle?
body: <p>From the documentation of <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html" rel="nofollow noreferrer">https://docs.oracle.com/javase/7/docs/api/java/util/Stack.html</a></p>
  
  <pre><code>public class Stack&lt;E&gt; extends Vector&lt;E&gt;
  </code></pre>
  
  <p>Isn't this a violation of the Liskov substitution principle? The LSP in simple terms states that objects of the same superclass should be able to be swapped with each other without breaking anything.</p>
  
  <p>For example: Let us say that I have a function that takes a Vector as an input. If while calling a function I start passing it a Stack then it might break because Stack prevents random access of elements. </p>
  
  <pre><code>import java.util.*;
  
  class Book {}
  
  class TextBook extends Book {}
  
  public class Sample {
      public static void process(Vector&lt;Book&gt; books) {
          # This should not be allowed for Stack, Stack is FILO
          System.out.println(books.get(1));
      }
  
      public static void main(String[] args) {
          Vector&lt;Book&gt; books = new Vector&lt;&gt;();
          books.add(new Book());
          books.add(new Book());
          books.add(new Book());
          process(books);
          System.out.println("ok");
  
          Stack&lt;Book&gt; bookz = new Stack();
          bookz.add(new Book());
          bookz.add(new Book());
          bookz.add(new Book());
          process(bookz);
          System.out.println("ok");
      }
  }
  </code></pre>