This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: using lambda to implement one method interface
- From: Per Bothner <per at bothner dot com>
- To: Sudarshan S Chawathe <chaw at eip10 dot org>, Sonny To <son dot c dot to at gmail dot com>
- Cc: Kawa mailing list <kawa at sourceware dot org>
- Date: Mon, 18 Sep 2017 07:22:56 -0700
- Subject: Re: using lambda to implement one method interface
- Authentication-results: sourceware.org; auth=none
- References: <22802.1505733729@vereq.eip10.org>
On 09/18/2017 04:22 AM, Sudarshan S Chawathe wrote:
how would I implement an interface with multiple methods?
I have found that simply defining the methods required by an interface
(with the proper names and type signatures) works, in the sense that the
resulting objects can be used anywhere that requires objects
implementing the interface.
Not sure I understand what you mean by that.
The problem is defining an instance of an interface:
(1) with multiple methods;
(2) on-the-fly, in a REPL;
(3) on Android, which doesn't (didn't?) have ClassLoader.defineClass.
It should be possible to generalize gnu.kawa.reflect.ProceduralProxy
to handle multiple methods and corresponding implementing procedures.
The tricky is specifying which method is implemented by which procedure.
Perhaps problem (3) above is no longer a problem, at least on Android 8.
https://developer.android.com/reference/java/lang/ClassLoader.html
says that the byte array to defineClass "should have the format of a valid
class file as defined by The Java™ Virtual Machine Specification."
So maybe we need to update the compilerAvailable test in ModuleExp.java.
If we now can generate classes on-the-fly then that removes a major
limitation of Kawa on Android. (At least on newer Android versions.)
--
--Per Bothner
per@bothner.com http://per.bothner.com/