Generics?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Generics?

frusso@email.it
Hi everybody,
I'm a BeanShell newbie and after playing for a while with BeanShell  
I've found out that maybe generics are not supported. Is it true?
According to my tests it seems to me that the problem is in locating  
(via reflection?) the right method to invoke. The scenario I'm dealing  
with foresees a bsh script that should create new instances of a  
generic class as follows:

  m1 = new BiDimMatrix<Integer>(0);
         m2 = new BiDimMatrix<Integer>(0);

         for(int i=0; i<size; i++) {
             m1.setValue(1, i,i);
             m2.setValue(2, i,i);
         }

The BSH runtime seems unable to find the constructor. If I add to  
BiDimMatrix a new non-generic constructor BSH finds it but fails  
invoking "setValue(T, int...)" since it is generic as well. Once  
again, if I add a non-generic "setValue" method it gets resolved.

Unlikely I cannot add all these non-genric methods, otherwise I had  
already "solved" my problem :P...
so the question are:
1. are my hipotesys on BSH correct?
2. are there any plans to enhance BSH supporting generics?

Thanks in advance,
Francesco
 
 
 --
 Email.it, the professional e-mail, gratis per te: http://www.email.it/f
 
 Sponsor:
 Cosa vuoi comunicare online? La risposta te la diamo noi: icecube communication, web design e comunicazione integrata
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=7353&d=30-12

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Generics?

Alexey Zinger
BeanShell doesn't support generics, but it's important to understand why.
Firstly, 1.5 syntax is not supported, except for autoboxing, which was
originally implemented before Java 1.5 anyway, in no small part, I suspect,
because all runtime BeanShell variables have to be reference types so as to be
storable in name space objects.  As for generics, look at how they're
implemented in Java -- through erasure, which means they only exist at compile
time.  Therefore, even if BeanShell supported Java 1.5 syntax, you couldn't
realistically enforce generics at runtime, except in cases of dynamic class
definitions.

--- "[hidden email]" <[hidden email]> wrote:

> Hi everybody,
> I'm a BeanShell newbie and after playing for a while with BeanShell  
> I've found out that maybe generics are not supported. Is it true?
> According to my tests it seems to me that the problem is in locating  
> (via reflection?) the right method to invoke. The scenario I'm dealing  
> with foresees a bsh script that should create new instances of a  
> generic class as follows:
>
>   m1 = new BiDimMatrix<Integer>(0);
>          m2 = new BiDimMatrix<Integer>(0);
>
>          for(int i=0; i<size; i++) {
>              m1.setValue(1, i,i);
>              m2.setValue(2, i,i);
>          }
>
> The BSH runtime seems unable to find the constructor. If I add to  
> BiDimMatrix a new non-generic constructor BSH finds it but fails  
> invoking "setValue(T, int...)" since it is generic as well. Once  
> again, if I add a non-generic "setValue" method it gets resolved.
>
> Unlikely I cannot add all these non-genric methods, otherwise I had  
> already "solved" my problem :P...
> so the question are:
> 1. are my hipotesys on BSH correct?
> 2. are there any plans to enhance BSH supporting generics?
>
> Thanks in advance,
> Francesco
>  
>  
>  --
>  Email.it, the professional e-mail, gratis per te: http://www.email.it/f
>  
>  Sponsor:
>  Cosa vuoi comunicare online? La risposta te la diamo noi: icecube
> communication, web design e comunicazione integrata
>  Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=7353&d=30-12
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://azinger.blogspot.com
http://bsheet.sourceforge.net
http://wcollage.sourceforge.net



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Loading...