E07270: trait methods cannot be marked with an access modifier, they are always public
What went wrong
You've added an access modifier (public/private/protected) to a trait method. Trait methods are always public by definition.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 106 (What are traits and how do I use them in EK9?)
Rationale
Traits define public contracts. Implementation details should be in the implementing classes, not the traits.
How to fix it
- Remove access modifier from trait methods
- Move private implementation to implementing class
Common causes
- Habit from class design
- Trying to hide trait implementation details
See also
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E07270: trait methods cannot be marked with an access modifier, they are always public
#!ek9 defines module error.e07270.bad defines trait Formatter format() -> amount as Integer <- rtn as String: prefix() + $amount //Every trait method is public private prefix() <- rtn as String: "#"
Fixed: Remove the access modifier
#!ek9 defines module error.e07270.good defines trait Formatter format() -> amount as Integer <- rtn as String: prefix() + $amount prefix() <- rtn as String: "#"
Questions and answers
These Q&A entries show E07270 and its fix: