• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
David Fisher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15205
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Why don't you just try it out and see what happens?
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic