strelok
06/20/2017, 2:27 AMpublic abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>> extends OptionalIdentifiedDefinition<Type> implements Block, OtherAttributesAware {
// ... stuff ...
public Type transform(Expression expression) {
// ...
return (Type) this;
}
}
I wrote the following extension method in kotlin:
fun <B, Type : ProcessorDefinition<Type>> ProcessorDefinition<Type>.transformBody(func: (B) -> Any): Type {
return this.transform(KotlinBodyFunctionExpression(func))
}
So KotlinBodyFunctionExpression
is just a simple adapter class to adapt a Kotlin function to an Expression
mentioned in the above Java class. I am only able to use this extension function like this though:
// this is Apache Camel btw that I am trying to extend
from("direct:start")
.setBody(constant("1.0"))
.transformBody { body: String -> BigDecimal(body) } // just superficial example
.to("mock:end")
I am trying to find a way where I can just write .transformBody<String> { BigDecimal(it) }
?
When I write that I get a compiler error: Error:(36, 25) Kotlin: 2 type arguments expected for fun <B, Type : ProcessorDefinition<Type>> ProcessorDefinition<Type>.transformBody(func: (B) -> Any): Type defined in com.test.package