Anonymous Objects

This commit is contained in:
Andrey Breslav
2010-11-19 11:09:23 +03:00
parent 661931469b
commit 8beb0da924
6 changed files with 69 additions and 11 deletions
+21
View File
@@ -0,0 +1,21 @@
addMouseListener(object MouseAdapter() {
private var clickCount = 0;
override fun mouseClicked(e : MouseEvent) {
clickCount++;
if (clickCount > 3) GOD.sendMessage(GodMEssages.TOO_MANY_CLICKS);
}
})
enum class GodMessages {
TOO_MANY_CLICKS
ONE_MORE_MESSAGE
}
// Type of this variable is GOD_AnonymousClass
val GOD = object {
fun sendMessage(message : GodMEssage) = throw new RuntimeException(message.name)
};
addMouseListener([mouseClicked : {e => doFoo()}]);
+13
View File
@@ -0,0 +1,13 @@
class ConcreteClass {
this() {}
}
// Implicitly generated a factory for ConcreteClass with a no-argument factory method
interface class IFooBarInterface {
new () { }
}
factory
+2
View File
@@ -0,0 +1,2 @@
l filter {it.x} map {it.foo} aggregate {a, b => a + b}