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 Can you delete the elements of a static Vector from another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can you delete the elements of a static Vector from another class" Watch "Can you delete the elements of a static Vector from another class" New topic
Author

Can you delete the elements of a static Vector from another class

David Fisher
Greenhorn

Joined: Mar 07, 2013
Posts: 2
Hey guys is it possible to delete the elements of a static Vector from another class? For E.g.
Suppose we have a

And you want to delete the elements of this static Vector from another class:

Would this work?
Thanks

David
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Welcome to the Ranch.

Why don't you just try it out and see what happens?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Welcome to the Ranch
I would have added code tags to your post, which would have made it look better, but you had not idented the code.

The answer to your question is yes, and no.
Just because that code will compile and run (try it, when you have got rid of the spelling error in class) doesn’t mean it isn’t really poor design. I hope that is simply, “I wanted to see what happens if…” code.
David Fisher
Greenhorn

Joined: Mar 07, 2013
Posts: 2
Thanks guys. It did work but I know its a bad design. I just wanted to quickly find out if it worked. It was required in one of the method stub for a project that I'm doing. Basically its an Android project which has a number of classes and objects interacting with each other, etc. I'm new to the JavaRanch forums so pardon me


David
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
Still bad design. You are using that List as a global variable, which is dubious. You can make it available via get methods. Or you can provide addToList(T t) and removeFromList(T t) methods, and make the List private.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you delete the elements of a static Vector from another class
 
Similar Threads
Object to int?
stack
Help
retrive Vector from HashMap
What the hell is a serialized object?