Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typed collections in Smalltalk

Tags:

smalltalk

I'm trying to learn some smalltalk programming.... I'm trying to create a list of objects of type myClass. What's the best way to do this?

I have the following:

| list |
list := OrderedCollection new.

Correct me if I'm wrong.

So how should I add elements to my list?

like image 799
user69514 Avatar asked Dec 07 '22 06:12

user69514


1 Answers

To create new instances of MyClass send the class the message #new

MyClass new

Now, to add an element to a collection, just send the collection the message #add:

list add: MyClass new

There is no such a thing as static types in Smalltalk. In other words, the equivalent of the Java ArrayList<MyClass> is just OrderedCollection.

like image 134
Damien Cassou Avatar answered Jan 01 '23 22:01

Damien Cassou