Okay, so now I have a shiny new Inline::Java I want to play with it...

    use Inline (
        Java => 'STUDY',
        STUDY => [qw(java.sql.DriverManager)],
        AUTOSTUDY => 1,
    );

    warn "getLoginTimeout: ". java::sql::DriverManager->getLoginTimeout;

    my $drivers_enumeration = java::sql::DriverManager->getDrivers;
    warn $drivers_enumeration;

    $drivers_enumeration = cast('java.util.Enumeration', $drivers_enumeration);
    warn $drivers_enumeration;

    while ($drivers_enumeration->hasMoreElements) {
            warn "Driver: ".$drivers_enumeration->nextElement;
    }

That says:

    getLoginTimeout: 0 at test.pl line 19.
    main::java::util::Vector::1=HASH(0x194b990) at test.pl line 22.
    main::java::util::Enumeration=HASH(0x19a31c0) at test.pl line 24.

without the cast() is says:

    main::java::util::Vector::1=HASH(0x194b834) at test.pl line 21.
    You are not allowed to invoke method hasMoreElements in class 
java.util.Vector$1: null at (eval 14) line 76
     at test.pl line 22

java.sql.DriverManager.getDrivers is declared to return an Enumeration.
I think that means that it can return anything it likes so long as
whatever it does return supports the Enumeration interface. Right?

[At this point you should assume, correctly, that I know nothing about
Java. I've only been using it for, oh, about 15 minutes ;-]

But how come I get the "You are not allowed to invoke method" unless I
use the cast() function?

Do I really have to sprinkle casts() all over the place?

Tim.

Reply via email to