0

Like java, I want to create a method that accepts an array list of particular object type.

In java:

public void addStudents(List<Student> students) {
...
}

In actionscript

public function addStudents(students:ArrayCollection):void {
.....
}

Here I want to have public function addStudents(students:ArrayCollection).

Thanks

3
  • Uh, and where is the problem? Is something wrong with mx.collections.ArrayCollection? Commented Sep 24, 2010 at 0:58
  • If I do this, some one can pass some other object array as well. Commented Sep 24, 2010 at 1:10
  • it will fail later on but I want to stop them and ask explicitly to pass an array of student type objects. Commented Sep 24, 2010 at 1:11

2 Answers 2

3

If you have a Student object and publish for FP10 you can use the Vector object.

public function addStudents(students:Vector.<Student>):void {}

For further information: http://help.adobe.com/en_US/AS3LCR/Flash_10.0/Vector.html

Sign up to request clarification or add additional context in comments.

Comments

1

As far as i know, AS has no template-like generics. But you can extend ArrayCollection into something like StudentArrayCollection with more rigid type check inside.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.