Menu

Accessing Java Classes

2004-12-19
2013-03-22
  • Rainer Hahnekamp

    Hi,

    in javascript I can easily access classes from the JAVA API with e.g. java.lang.System.out("Hello");respectively classes within the classpath with Packages.org...

    Is there a similiar possibilility in BsfPerl?

     
    • Don Schwarz

      Don Schwarz - 2004-12-19

      There is now.  You can call static methods like this:

      import java::lang::Math;
      my $v = Math->sin(0.5);

      You can also instantiate Java objects:

      import java::util::Random;
      my $r = new Random();
      my $v = $r->nextInt;

      However, there is not currently a way to access static Java fields.  This is planned for BSFPerl v0.3.  However, if all you want to do is call System.out.println, you should just be able to use "print" from Perl.  For example:

      print "Hello\n";

      Let me know if you have any further questions,
      Don

       
    • Rainer Hahnekamp

      Hi Don,

      I just wanted to ask when BSFPerl v0.3 will be out since I would need the functionality to access static methods.

       

Log in to post a comment.