www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

digitalmars.D - Java Array --> D Array

↑ ↓ ← Brad Anderson <brad dsource.dot.org> writes:
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
Jul 03 2004
↑ ↓ Sam McCall <tunah.d tunah.net> writes:
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
Jul 03 2004
↑ ↓ Brad Anderson <brad dsource.dot.org> writes:
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
Jul 03 2004
Brad Anderson <brad dsource.dot.org> writes:
         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
Jul 03 2004
↑ ↓ → Sam McCall <tunah.d tunah.net> writes:
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.

Sam
Jul 03 2004
"Walter" <newshound digitalmars.com> writes:
"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;
Jul 03 2004
↑ ↓ → Andy Friesen <andy ikagames.com> writes:
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
Jul 03 2004