RE: method signature specificity when using interface types

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

RE: method signature specificity when using interface types

Chris Greener
this is an old email re-posted by the list server, please ignore.
i looked into the source and found my answer, beanshell throws away the return type after executing the java method.
it looks like it would be fairly simple to track this type information in the future by adding the return type to a global hash for a given object reference.
this would allow for improved specificity when resolving method calls.

From: [hidden email] [mailto:[hidden email]] On Behalf Of Chris Greener
Sent: Friday, November 04, 2005 8:34 AM
To: [hidden email]
Subject: [Beanshell-users] method signature specificity when using interface types

Friends, I'm seeing an issue with beanshell choosing the wrong method signatures when using interface types.
If the following java code below is called from beanshell it seems to incorrectly select the wrong display method signature. see output below
Another issue I'm seeing (not illustrated here) is when methods have ambiguous java signatures, beanshell executes the first method it finds.
This still happens even if the method call is explicitly typed from beanshell.
I'm trying to understand the extent of these issue and any workarounds. I'm maily concerned by the first issue as our interface implementations are broad and its somewhat difficult to detect when this happens. I first noticed this when application behaviour changed as method order in the compiled java source changed.
output from below
java IFoo
shell IFoo2    // this is incorrect - should have used method signature with IFoo
java IFoo2
shell IFoo2
// beanshell calling code
IFoo foo = Foo.createIFoo();  //should display IFoo

Foo.display( foo, "shell" );    //should display IFoo

IFoo2 foo2 = Foo.createIFoo2(); // should display IFoo2

Foo.display( foo2, "shell" );  // should display IFoo2

// java compiled code start here
public interface IFoo {

public interface IFoo2 {

public class Foo implements IFoo, IFoo2 {
    public String name = "Foo";

    public static IFoo createIFoo() {
        IFoo f = new Foo();
        Foo.display(f, "java");
        return f;

    public static IFoo2 createIFoo2() {
        IFoo2 f = new Foo();
        Foo.display(f, "java");
        return f;

    public static void display( IFoo f, String t ) {
        java.lang.System.out.println(t + " IFoo");

    public static void display( IFoo2 f, String t ) {
        java.lang.System.out.println(t + " IFoo2");