E07090: 'default' modifier is only valid for constructors, not regular methods
What went wrong
You've used 'default' modifier on a regular METHOD, but 'default' is only valid for constructors and operators.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 109 (How do I use composition instead of inheritance in EK9?)
How to fix it
- Remove 'default' from method
- Provide explicit implementation
- Use 'default' only on constructors or operators
Common causes
- Confusion about 'default' keyword purpose
- Trying to provide auto-generated method
- Misunderstanding which constructs support default
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07090: 'default' modifier is only valid for constructors, not regular methods
#!ek9 defines module error.e07090.bad defines record R1 prop1 <- String() //Valid: default constructor default R1() //Invalid: default on regular method in record default getValue() <- rtn as String: String(prop1) defines trait T1 //Invalid: default on regular method in trait (with body) anotherMethod() as pure abstract -> text as String <- rtn as String? default someMethod() as pure -> text as String <- rtn as String: String(text) //Valid: abstract method without default defines class C1 //Valid: default constructor default C1() //Invalid: default on regular method with body default normalMethod() -> text as String <- rtn as String: String(text) //Valid: regular method without default validMethod() -> text as String <- rtn as String: String(text) defines component Comp1 //Valid: default constructor default Comp1() //Invalid: default on regular method in component default processData() -> data as String <- rtn as String: String(data)
Fixed: Remove 'default' from the method
#!ek9 defines module error.e07090.good defines class Greeter //'default' is fine on a constructor default Greeter() //A method is written, never 'default' greet() -> greeting as String <- rtn as String: String(greeting)
Questions and answers
These Q&A entries show E07090 and its fix: