Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

groovy 'Alpha$TraitAdapter' implements trait 'Alpha' but does not extend self type class 'Thing'

I'm doing some experiments with traits in scriptrunner and am running the following code in the console

import groovy.transform.SelfType

class Thing {
String color

Thing(String color) {
this.color = color
}

String doSomething() {
"something"
}

@Override
String toString() {
"${color} thing"
}
}

//@SelfType(Thing)
trait Alpha {
String alpha() {
"alpha ${this}"
}

String alphaSomething() {
"alpha ${this.doSomething()}"
}
}

StringBuilder out = new StringBuilder()

out << "<pre class=\"dark\">\n"

Thing blueThing = new Thing("blue")
out << "${blueThing} (${blueThing.class})\n" // blue thing (class Thing)

def alphaThing = blueThing.withTraits Alpha
out << "${alphaThing} (${alphaThing.class})\n" // Thing18_groovyProxy@236366b2 (class Thing18_groovyProxy)
out << "${alphaThing.doSomething()}\n" // something
out << "${alphaThing.alpha()}, ${alphaThing.alphaSomething()}\n" // alpha Thing18_groovyProxy@236366b2, alpha something

out << "</pre>\n"

out.toString()

 

When I remove the comment on @SelfType(Thing) I get the following compilation error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Alpha$TraitAdapterwrapper: -1: class 'Alpha$TraitAdapter' implements trait 'Alpha' but does not extend self type class 'Thing' @ line -1, column -1. 1 error

 

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Software

👋 Looking for 15-20 volunteers to test Atlassian training content

Hi everyone! Are you interested in beta testing Atlassian University’s newest (unreleased!) training course? We’re looking for 15-20 volunteers to test our newest training course, Basic reporting...

816 views 24 28
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you