Revision history [back]

click to hide/show revision 1
initial version


The design of the Java bindings is a result of the decision to expose AllJoyn interfaces as Java Interfaces. The C++ language does not have built in way to create interfaces. The best you can do is create a class with pure virtual functions that represents an interface. The Java language on the other had has the concept of Interfaces built into the language. Early on it was decided to expose the AllJoyn interface as a Java interface in the Java language bindings. To do this Annotations were added to the Java interface that could be read using reflection. The annotations provided the extra information needed to convert a Java interface to an AllJoyn interface.

This decision has some major benefits. When implementing a BusObject you are just implementing an interface. Implementing an interface is understood by the Java language and prevents the programmer from making some of the mistakes that are easy to make in C++. For example, if your AllJoyn interface has a method named Foo() and you map it with the name foo() (note difference in capitalization) it will not work. Since in C++ this is all done using strings the compiler will not catch the mistake. In Java you will get a compiler error. There are some other benefits. The biggest reason (to the best of my knowledge) was to make programming feel familiar for someone that primarily programs in Java.

The two major drawbacks of this early design decision are. 1. We don't have a way to generate a Java interface with all the required annotations at run-time this means the interface must be provided at compiler time. 2. Method calls are done synchronously. (This issue has a work around using concurrent callbacks and threads.)

So to answer you question. Java's inability to create interfaces via introspection is a result of an early design decision made to use Java's built in language interface to represent an AllJoyn interface. The design decision permeates the JNI code and is not simple to change. It may not be possible to implement run-time creation of AllJoyn interfaces in Java with out a major rework of the Java language bindings.