In Groovy, you can use trait instead of a class. Since they act similarly to abstract classes (that way, you can specify abstract methods, but you can still implement others), you can do something like:
trait EmployeeTrait { int getId() { return 1000
Just note that this is not exactly the same as extending two classes, but in some cases (for example, in the above example), this may resolve the situation. I highly recommend analyzing your design before moving on to using attributes, they are usually not required, and you cannot implement inheritance nicely (for example, you cannot use protected methods in attributes). Follow the recommendations of the accepted answer, if possible.
lepe Aug 26 '19 at 9:02 2019-08-26 09:02
source share