This site requires JavaScript, please enable it in your browser!
Greenfoot back
darkmist255
darkmist255 wrote ...

2012/5/14

Just wondering if this is possible

darkmist255 darkmist255

2012/5/14

#
Let's say I do "someList = getSomeList(Something.class)" and it returns a list of objects, is there a way to do "someList.someMethod()" to call "someMethod()" in all of the returned objects?
danpost danpost

2012/5/14

#
You mean like:
for (Object actor : getObjects(Light.class))  ((Light) actor).setLuminsAt(50);
darkmist255 darkmist255

2012/5/14

#
Yeah! That's kinda like what I read; could you clear up the individual parts? Is it like this: for (*the variable type* *variable name* : *the command to retrieve a list*) { *variable name*.*the method to execute*; }
danpost danpost

2012/5/14

#
Yeah! Make sure it is cast properly, so the compiler can find the method. Casting it in the 'for' statement gets a little messy (requiring 'List' objects and casts); that is why I cast it where I did.
You need to login to post a reply.