Tim,

On 9/2/05, Tim Bunce <[EMAIL PROTECTED]> wrote:

> 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

Seems you have stumbled onto a special case that Inline::Java does not
handle correctly. The object that is returned by
$drivers_enumeration->hasMoreElements() is in fact of type
java.util.Vector$1, which does implement the Enumeration interface.
So, in this case, Inline::Java sends information to Perl saying the
that object is of type java.util.Vector$1. Here is where is gets
tricky:

Ths class java.util.Vector$1 is an inner class, which in Java lingo
means that this class is defined inside another class and cannot be
instantiated outside of the container class (in this case
java.util.Vector). But that is not the problem here bacause
Inline::Java can handle this. The problem is that the
java.util.Vector$1 class is not public, which means that it cannot be
accessed from outside the java.util package. That's why you are
getting that error when you call the method on java.util.Vector$1.

Even in pure Java you can't do it :

This compiles:
  class sql {
      public static void test(){
          java.util.Enumeration e = java.sql.DriverManager.getDrivers() ;
          e.hasMoreElements() ;
      }
  }

this doesn't :
  class sql {
      public static void test(){
          java.util.Vector$1 e = java.sql.DriverManager.getDrivers() ;
          e.hasMoreElements() ;
      }
  }

I did not know that it was possible to do this, i.e. extend/implement
a public class/interface in a non-public way.

I guess the real way to solve this problem is to change the way
Inline::Java returns class type and uses casts. Instead of returning
the real object type to Perl and have the user cast to force the more
generic type, maybe it should return the type that the method returns
and have the user cast to force the more specific type. But then that
would make Inline::Java more Java-ish and less Perl-ish... I'm not
sure which is best.

For know you can keep using cast like you did, but you shouldn't have
to do it to often. This is the first time I've heard of something like
this.

Also, I'd like to point out that you could make your life a whole lot
simpler by accessing your database directly from Perl. You should
really take a look at DBI. It's great.  ;)

BTW: If anyone has suggestions on the best way to handle this, don't
hesitate to let me know.

Patrick


> 
> Tim.
> 
-- 
=====================
Patrick LeBoutillier
Laval, Québec, Canada

Reply via email to