
-----------------------------------
wtd
Mon Jul 09, 2007 12:14 pm

A challenge
-----------------------------------
What did I do wrong in the following code?

class Foo {
   public int[] bar() {
      /* code omitted */
   }
}

class Baz {
   private Foo f;

   public Baz() {
      f = new Foo();
   }

   public void qux() {
      for (int i : f.bar()) {
         System.out.println(i);
      }
   }
}

-----------------------------------
Dan
Mon Jul 09, 2007 2:47 pm

RE:A challenge
-----------------------------------
Are we sposted to reply by posting or PMing you :p. Also are there sposted to be more then one thing wrong?

-----------------------------------
wtd
Mon Jul 09, 2007 3:34 pm

RE:A challenge
-----------------------------------
There is supposed to be one thing wrong.  Or at least, I am looking for one thing specifically.

The code omitted is not the problem.  Assume that it returns an array of ints via some mechanism that is irrelevant to the question.

Please post.  First come, first serve.

-----------------------------------
Dan
Mon Jul 09, 2007 4:15 pm

RE:A challenge
-----------------------------------
Well i could be wrong but public qux() needs a return type in it's deftion or has to have void.

I don't think this is what you meant tho. I have not seen a for loop done like that so i am not shure if it would work, i shall look at it more latter.

-----------------------------------
wtd
Mon Jul 09, 2007 4:57 pm

RE:A challenge
-----------------------------------
Indeed, it is not what I had in mind.  

The loop is a 1.5+ for-each loop.

-----------------------------------
wtd
Mon Jul 09, 2007 7:17 pm

RE:A challenge
-----------------------------------
For fun, in another language:

class Foo {
   public def bar: Array[Int] = /* Code omitted */
}

class Baz {
   private val f: Foo = new Foo

   public def qux {
      for (val i 