Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wierd java syntax encountered

Status
Not open for further replies.

redsss

Programmer
Mar 17, 2004
72
US
I downloaded some java code which contained a line like so:
Code:
for (MidiSynthListener t : c){
Compiling gave me the following error:
MidiSynth.java:182: illegal start of expression

Any idea what this is about? I think the code is for java 1.5 (not sure if its backwards compatable), whereas my sdk is 1.4.2, would that possibly be the problem?
 
In short, yes it's the new enhanced for loop in J2SE5.0. c is a collection containing MidiSynthListener objects. The loop will iterate over the collection c giving you the objects in the iteration in the t instance variable.

Tim
 
Code:
for (MidiSynthListener t : c){

From what I've read of the new Beta, and the comment above... That means this would read as:

Code:
for( int i = 0; i < c.size(); ++i)
{
   MidiSynthListener t = (MidiSynthListener)c.getAt(i);

yes? no?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top