Given the following class hierarchy: ``` class Pro...
# announcements
v
Given the following class hierarchy:
Copy code
class 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:
Copy code
val generator = GeneratorAdapter()
val property = PropertyAdapter()

property.generateRead(generator, PropertySpec())
property.generateWrite(generator, PropertySpec())
But the same code works fine in Java:
Copy code
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:
Copy code
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?