BAEL-2726_Introduction_to_Traits_in_Groovy (#6384)

This commit is contained in:
Anshul Bansal 2019-02-20 20:13:53 +02:00 committed by maibin
parent 156441843c
commit 2f9bc1b54a
5 changed files with 21 additions and 2 deletions

View File

@ -0,0 +1,3 @@
package com.baeldung
class Car implements VehicleTrait {}

View File

@ -22,7 +22,7 @@ trait UserTrait implements Human {
msg
}
def whoAmI() {
def self() {
return this
}

View File

@ -0,0 +1,9 @@
package com.baeldung
trait VehicleTrait extends WheelTrait {
String showWheels() {
return "Num of Wheels $noOfWheels"
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung
trait WheelTrait {
int noOfWheels
}

View File

@ -57,7 +57,7 @@ class TraitsUnitTest extends Specification {
def 'Should return employee instance when using Employee.whoAmI method' () {
when:
def emp = employee.whoAmI()
def emp = employee.self()
then:
emp
emp instanceof Employee