By the look of it your VB
code exposes the collection as a public piece of data. Ie, calling it myPrivateList
is a bit misleading as it isn't, in any real sense, private. Precisely because the two forms you give are functionally equivalent one is neither more nor less "OOP" than the other. Anyone who would frown on one but smile on the other is following a rule, not exercising judgement.
The same functionality would be achieved in Java by making it a public member variable. (The difference between the languages is that VB
has a bit of sugar allowing you to write functionality like a method, but invoke it like a field. Java programmers would probably dislike the taste of the sugar: preferring to see from the syntax what manner of thing they are dealing with. But it is a matter of taste.)
In Java collections are a reference type, and are passed about as copies of pointers. The languages don't really differ in that respect.
Rather than worrying about whether this is OOP or whatever, it might be more instructive to consider what could go wrong (in either language)
(1) An instance of MyClass can have its collection data changed to a different collection by another class. And it won't know anything about it. The solution here is to provide a setter that responds to the change, or not have a setter in which case the collection really will be private in the sense that no-one outside the class can alter which collection is being used. (In VB
the response would go in the Set part, or there could be no Set functionality.)
(2) An instance of MyClass can have the contents
of its collection data altered without knowing anything about it. Ie the caller can add or remove things from the collection once it has a reference to it. The solution here is to provide a getter that returns a copy
of the collection, so callers can only monkey about with the copy, not the collection that is part of the MyClass instance. Or you could not provide a getter at all but provide specific methods to allow specific behaviour involving the collection.
This last alternative (no getter or setter) even hides the state of the things in the collection from the caller! The caller asks for something to be done: it doesn't ask to be told what the MyClass instance's data is.