1 /*
   2  * This is the test JavaScript program used in jjs-fileTest.sh
   3  */
   4 
   5 // good old 'hello world'!
   6 print('hello');
   7 
   8 // basic number manipulation
   9 var v = 2 + 5;
  10 v *= 5;
  11 v.doubleValue();
  12 v = v + " is the value";
  13 if (v != 0) {
  14     print('yes v != 0');
  15 }
  16 
  17 // basic java access
  18 java.lang.System.out.println('hello world from script');
  19 
  20 // basic stream manipulation
  21 var al = new java.util.ArrayList();
  22 al.add("hello");
  23 al.add("world");
  24 // script functions for lambas
  25 al.stream().map(function(s) s.toUpperCase()).forEach(print);
  26 
  27 // interface implementation
  28 new java.lang.Runnable() {
  29     run: function() {
  30         print('I am runnable');
  31     }
  32 }.run();
  33 
  34 // java class extension
  35 var MyList = Java.extend(java.util.ArrayList);
  36 var m = new MyList() {
  37     size: function() {
  38         print("size called");
  39         // call super.size()
  40         return Java.super(m).size();
  41     }
  42 };
  43 
  44 print("is m an ArrayList? " + (m instanceof java.util.ArrayList));
  45 m.add("hello");
  46 m.add("world");
  47 print(m.size());