Welcome! Please see the About page for a little more info on how this works.

0 votes
in Java Interop by

Here's my sample code.
Thanks.

// Java code
interface IFace {
  String message();
}
class A implements IFace {
  @Override message () { return "Hello A!"};
}
class B implements IFace {
  @Override message () { return "Hello B!"};
}
class PrintHello {
  static void print (IFace msg) {
    if (msg instanceof A) { ... } else { ... }
  }
}

; Clojure code

(def a (A.))
(. PrintHello (print a))

1 Answer

+1 vote
by

Changed Java code works for me (see comments):

public interface IFace {
    String message();
}

// Class should be public
public class A implements IFace {
    @Override
    public String message() {
        return "Hello A!";
    }
}

// Class should be public
public class B implements IFace {
    @Override
    public String message() {
        return "Hello B!";
    }
}

public class PrintHello {
    // Method should be public
    static public void print (IFace msg) {
        msg.message();
    }
}

(def a (A.))
(PrintHello/print a)
...