Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there commented-out code in native method?

Tags:

java

gwt

Recently, I've seen a lot of methods with the "native" keyword. It seems very common to have, what seems like, commented out code.

public native Something Foo(arg, arg) /*-{
    var foo = some.Method(arg);
    return foo;
}-*/;

I don't really understand what the commented-out portion is or why it's commented out. For a good while now I've thought that this was just commented out code. I'm starting to see it in more projects now (for instance, it's in the gwt source code).

Is the commented-out code significant in some way I don't understand? I've read about the native keyword, and I understand what it means and how it's used in a basic sense. It's just confusing to see this "commented-out code" so often.

Can someone explain the comments. Are they really comments? Are they significant?

[Update] The question was about the commented out portion. I was starting to see it often enough I thought there was some significance that I was missing. Something like an annotation, for instance. I just wanted to be clear onwhy there were commented out sections of code littered all over.

like image 849
loctrice Avatar asked Mar 15 '23 04:03

loctrice


1 Answers

Because the gwt code is compiled in two distinct part : java for the server part and javascript for the client one.

The comment syntax in native methods

  /*-{ some javascript code }-*/

is a gwt specific way to write native javascript in the gwt code.

See JSNI

like image 156
Gab Avatar answered Mar 24 '23 08:03

Gab