perl.inline
[Top] [All Lists]

Re: Inline Java Integer question

Subject: Re: Inline Java Integer question
From: mental@xxxxxxxxxxxxxx (Jason Stelzer)
Date: Fri, 18 Jul 2008 19:36:58 -0400
Newsgroups: perl.inline
Inline::Java does a pretty good job of auto-marshalling primitive types (from java.lang.*) for you without you having to do much about it yourself. In fact, Integer is one of those types that should 'just work'. However, to illustrate how you'd go about coercing the type, this example seems to work (I just changed the example from the pod to use Integer rather than int):

use strict;
use Inline Java => <<'END_OF_JAVA_CODE' ,STUDY => ['java.lang.Integer'],;
             class Pod_alu {
                public Pod_alu(){
                }

                public Integer add(Integer i, Integer j){
                   return i + j ;
                }

                public int subtract(Integer i, Integer j){
                   return i - j ;
                }
               public void showInteger(Integer i){
                 System.out.println("Integer is " + i);
               }
             }

END_OF_JAVA_CODE

my $alu = new Pod_alu() ;
print($alu->add(9, 16) . "\n") ; # prints 25
print($alu->subtract(9, 16) . "\n") ; # prints -7
my $int = Inline::Java::coerce('java.lang.Integer', 32);
print "Int is a $int\n";
$alu->showInteger($int);
$int = 400;
print "Int is a $int\n";
$alu->showInteger($int);





On Jul 18, 2008, at 5:00 PM, Vanole, Mike wrote:

Was: (Inline Integer question)

Re: Inline Java and the Business Objects SDK

I'm stuck on what I think it an integer input problem.

I need to make sure that I'm replicating this Java:

Integer groupInt = new Integer(iGroup.getID());

I can get a value from iGroup.getID(). That value is "2"

And I make sure it's an integer (perl):

$groupInt = int($iGroup->getID());

But I don't think this is a correct way to translate the Java above

I think I need coerce, but I couldn't make that work.

What is the correct way to ensure $groupInt is a Java integer?

Thanks,
Mike


--
Jason Stelzer
mental@xxxxxxxxxxxxxx



<Prev in Thread] Current Thread [Next in Thread>