Thread overview
Java Array --> D Array
Jul 03, 2004
Brad Anderson
Jul 03, 2004
Sam McCall
Jul 03, 2004
Brad Anderson
Jul 03, 2004
Brad Anderson
Jul 04, 2004
Sam McCall
Jul 03, 2004
Walter
Jul 03, 2004
Andy Friesen
July 03, 2004
I'm not terribly knowledgeable about Java arrays and all the permuatations of assignment and such.  I don't know what to make of the following:

// Java Code
public class Control : Widget , IDrawable {

  ...

  Control [] computeTabList () {
    if (isTabGroup ()) {
      if (getVisible () && getEnabled ()) {
        return new Control [] [this];         // not sure what this is.
      }
    }
    return new Control [0];
  }

  ...

}


The compiler complains about implicitly converting from Control to int, and I get that the array index should be integers, but what is Java doing with 'this' in the array index?

My first thought was that this is actually an assignment of the new Control[] that is done inside of [ ] in Java.  So I tried to use D's { }, but alas, it's not a static array.

Any assistance on how to turn this into D code?

BA
July 03, 2004
Brad Anderson wrote:
>         return new Control [] [this];         // not sure what this is.

Me neither, it's not valid java.
You probably want return new Control[] {this}, which creates a new Control array (dynamically) initialised to [this].
Sam
July 03, 2004
Sam McCall wrote:

> Brad Anderson wrote:
> 
>>         return new Control [] [this];         // not sure what this is.
> 
> 
> Me neither, it's not valid java.

But it is in the SWT code for 3.0 M6.  I can't imagine the Eclipse people would put something out that javac barfs on.  I'll look around in the final SWT code for 3.0.

> You probably want return new Control[] {this}, which creates a new Control array (dynamically) initialised to [this].

As for your suggestion, I had already tried that, but DMD said:

found '{' when expecting ';' following 'return statement'

I settled on this:

  Control[] ret;
  ret[0] = this;
  return ret;

which works, but only if I understand their true intent.

Thanks for the response, though
BA
July 03, 2004
>>
>>>         return new Control [] [this];         // not sure what this is.
>>
>>
>> Me neither, it's not valid java.
> 
> 
> But it is in the SWT code for 3.0 M6.  I can't imagine the Eclipse people would put something out that javac barfs on.  I'll look around in the final SWT code for 3.0.

Whoops.  It was {this} in Java (curly braces).  In any case, that doesn't work in D.  Sorry for the confusion.

Still wouldn't mind hearing if my work-around is on target.

Thx

July 03, 2004
"Brad Anderson" <brad@dsource.dot.org> wrote in message news:cc5opo$2cdr$1@digitaldaemon.com...
> I settled on this:
>
>    Control[] ret;
>    ret[0] = this;
>    return ret;

Try:
    Control[] ret = new Control[1];
    ret[0] = this;
    return ret;


July 03, 2004
Walter wrote:
> "Brad Anderson" <brad@dsource.dot.org> wrote in message
> news:cc5opo$2cdr$1@digitaldaemon.com...
> 
>>I settled on this:
>>
>>   Control[] ret;
>>   ret[0] = this;
>>   return ret;
> 
> 
> Try:
>     Control[] ret = new Control[1];
>     ret[0] = this;
>     return ret;

Satanic alternative:

    return (&this)[0 .. 1];

 -- andy
July 04, 2004
Brad Anderson wrote:

>>>
>>>>         return new Control [] [this];         // not sure what this is.
>>>
>>>
>>>
>>> Me neither, it's not valid java.
>>
>>
>>
>> But it is in the SWT code for 3.0 M6.  I can't imagine the Eclipse people would put something out that javac barfs on.  I'll look around in the final SWT code for 3.0.
> 
> 
> Whoops.  It was {this} in Java (curly braces).  In any case, that doesn't work in D.  Sorry for the confusion.
Oops, sorry, that's what I meant: the one I gave was Java, not D, sorry.
Sam