An anonymous class is commonly used in the Java platform where a
function language would use a lambda expression.
Examples are call-back handlers, events handlers, and run
methods.
In these cases Kawa lets you use a lambda expression as a short-hand
for an anonymous class. For example:
(button:addActionListener (lambda (e) (do-something)))
is equivalent to:
(button:addActionListener (object (java.awt.event.ActionListener) ((actionPerformed (e ::java.awt.event.ActionEvent))::void (do-something))))
This is possible when the required type is an interface or abstract class with a Single (exactly one) Abstract Methods. Such a class is sometypes called a SAM-type, and the conversion from a lambda expression to an anonymous class is sometimes called SAM-conversion.
Note that Kawa can also infer the parameter and return types of a method that overrides a method in a super-class.
http://www.gnu.org/software/kawa/Anonymous-classes.html#Lambda-as-shorthand-for-anonymous-class--
You received this message because you are subscribed to the Google Groups "yeti-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yeti-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
If you can grep all the Interface/method names how about writing a code-generator which wirtes you a yeti-module whith all the yeti-wrapers as Madis suggested (you could also use a dynamic proxy to save code-size)I know that is not the ideal solution however IMO the problem is that there are many whishes which only Madis can fullfill and he is a bit short of time - AFAIK - and would rather need some help from us. And having such a module for Android would certainly help.
--
Well you can do it, if you want. It would be a new automatic cast, and easiest way to implement it would be probably an AST transformation in analyze phase. Basically you would detect a method-argument cast, and if the types are suitable, generate an AST or code objects corresponding to the following:
(class generated-id extends RequiredType
abstract-method-signature lambda argument
end; new generated-id())
Since it's use case is argument to foreign methods, you have to consider method overrides.
Note that I suggest not touching the given lambda and just producing an
application - afaik the code generation stage should inline such lambda application, so there is no benefit in trying to do it before.
I personally don't see much benefit from it (counting all the callback interfaces in Java APIs is imho meaningless, as you are unlikely to use more than fraction of those in any given application), but it won't clutter the syntax, and it seems that the implementation shouldn't take more than about hundred lines of additional code in the compiler.
So if you produce working non-bloated patch, I'll accept it.