vmironov
02/23/2016, 1:10 AMclass PropertySpec()
class GeneratorAdapter()
class PropertyAdapter() {
fun GeneratorAdapter.generateRead(property: PropertySpec) = println("read")
fun GeneratorAdapter.generateWrite(property: PropertySpec) = println("write")
}
Is it possibe to invoke generateRead
and generateWrite
methods outside of PropertyAdapter
context? The following code doesn't compile in Kotlin:
val generator = GeneratorAdapter()
val property = PropertyAdapter()
property.generateRead(generator, PropertySpec())
property.generateWrite(generator, PropertySpec())
But the same code works fine in Java:
final GeneratorAdapter generator = new GeneratorAdapter();
final PropertyAdapter property = new PropertyAdapter();
property.generateRead(generator, new PropertySpec());
property.generateWrite(generator, new PropertySpec());
The only workaround I've found so far is to use property.apply {}
syntax:
val generator = GeneratorAdapter()
val property = PropertyAdapter()
property.apply { generator.generateRead(PropertySpec()) }
property.apply { generator.generateWrite(PropertySpec()) }
Questions:
1. Is is possible to invoke generateRead
and generateWrite
without wrapping it into a lambda expression?
2. If no, then should it be considered as a bug?