https://kotlinlang.org logo
r

rrader

09/11/2017, 8:11 AM
@bamdmux can you show an example?
In your case assuming you have
Copy code
interface Product {
val title: String
val desc: String
}
You define
Copy code
class Clothing(val p: Product, val size: Long): Product by p
r

rrader

09/11/2017, 8:29 AM
this is not really the same, I updated the issue on github so,
class Clothing(@Embed product: Product, val size: Long)
will be transformed to class Clothing(title: String, description: String, val size: Long) : Product(title, description)
e

evanchooly

09/11/2017, 8:29 AM
one of my favorite features...
r

rrader

09/11/2017, 8:31 AM
in your version I even don't need delegation I can write
class Clothing(val p: Product, val size: Long)
however, this is not desired
b

bamdmux

09/11/2017, 8:32 AM
No, what delegation does
is that you can directly call the delegation entities
Assuming c is a Clothing, with delegation you can use
c.name
or
c.description
r

rrader

09/11/2017, 8:33 AM
even in Java?
For me it is more inconvenient on create object than using the object. I really want class to have the signature
Clothing(title: String, description: String, val size: Long) : Product(title, description)
but I don't want to duplicate everytime this part
title: String, description: String
and
Product(title, description)
b

bamdmux

09/11/2017, 8:41 AM
What do you mean "in Java"? The compiler will generate the java bytecode for the delegated methods
But if what you want is have a class with the constructor signature
Clothing(name, desc, size)
Class delegation wouldnt do that for you
r

rrader

09/11/2017, 8:45 AM
Thanks. Than it does not solve the issue.