Vote count:
0
So I have the same issue as here and here. I have classes A and B. A shall be decorated by B. To save my some typing, I use the @delegate groovy annotation so that groovy handles all the calls to Bs methods and automatically deligates them to an A type object that is saved in B.
This works fine, however I do not get any help from compiler. If I try myB.someMethodOfClassA() then the compiler is not smart enough to figure out, that this method call will be delegated to A and that such a method is present in A, so it marks it as not found - at runtime it will still work.
I can workaround that by having B also extends from A. However, then As default-constructor is called when initializing B and if there is none, it fails of course.
One (clean) solution would be to create an AInterface and let A and B implement it. Is there another (clean) way of doing what I want without having to create an interface all the time? (I might even not be able to do that if A is not under my control)
use delegate annotation + extends for groovy class without default constructor call
Aucun commentaire:
Enregistrer un commentaire