Nice TWiki > Doc > NiceTutorial > UsingJavaFromNice (r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
This topic gives some tips and hints how to use Java from Nice

nice -> static java method

javanice
package test;

public class Foo {
 static public String sayHello() {
  System.out.println("hello");
 }   
}
package test;

public void main(String[] args) {
 Foo.sayHello();
}

nice -> static java function

javanice
package test;

public class Foo {
 static public String sayHello() {
  return "hello";
 }   
}
package test;

public void main(String[] args) {
 println(Foo.sayHello());
}
package test1;
import java.util.*;

public class Foo {
   static public List getList() {
      List l = new ArrayList();
      l.add("one");
      l.add("two");
      
      return l;
   }
}
package test1;
import java.util.*;

List<String> getList() = native List Foo.getList();

public void main(String[] args) {
   getList().foreach(String s => println(s));
}

-- AlexGreif - 07 Mar 2003

I'm not sure why you distinguished methods (returning void?) and functions. I think the point here is that if the Java code uses parameterized types (like List, Collection, Map, ...), then you need a native declaration in Nice to specify their precise type.

Note: your List was printed in Wiki as List, because was interpreted as a tag. I did not understand a thing at first because of that, and thought there was a bug in the compiler! :-) I added verbatim in addition to pre to solve this problem. Isn't there a simpler way, like a tag? Could be define that in TWiki? -- DanielBonniot

Topic UsingJavaFromNice . { Edit | Attach | Ref-By | Printable | Diffs | r1.3 | > | r1.2 | > | r1.1 | More }
Revision r1.2 - 07 Mar 2003 - 13:23 GMT - DanielBonniot
Parents: WebHome > NiceTutorial
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.