File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem with stack class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with stack class" Watch "Problem with stack class" New topic
Author

Problem with stack class

sovan chatt
Ranch Hand

Joined: Aug 09, 2010
Posts: 43
removeElementAt() method is available in vector class so,its also available to stack class ..but using this method any element can be eliminated..which cannot be a proper implementation of stack... or is it?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

No, it's not ideal. Those are classes from the original version of Java, and if they were added now I suspect they'd be designed differently - I'd expect to see Stack as an interface, with some class (possibly one of the existing collections) implementing it. A bit like the way LinkedList implements the Queue interface nowadays.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Agreed. This is one example of incorrect inheritance. A stack is not a vector, so Stack should not extend Vector. Similarly, a property list is not a hash table, so Properties should not extend Hashtable. In both cases, composition would have been preferable. There is one item also listed in Effective Java related to this.


http://muhammadkhojaye.blogspot.com/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
You ought to use this instead of Stack.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with stack class
 
Similar Threads
Variables
Stack
itemAt Stacks
what is a stack trace
Thread.currentThread.hashcode() returns zero?