E01075: 'new' does not exist in EK9 - instantiate types with TypeName() directly
What went wrong
The 'new' keyword does not exist in EK9.
Worked examples
Compilable examples demonstrating this error and the correct fix:
- ek9 -q 148 (How do I migrate complex control flow from Java or Python...)
Rationale
EK9 simplifies object creation - just call the type directly:
- No 'new' keyword needed (like Python, Kotlin)
- Cleaner syntax: Person("Steve") vs new Person("Steve")
- Type inference works naturally with direct calls
- Less visual noise, more readable code
How to fix it
Remove 'new' and call the type constructor directly. TypeName() creates an instance - no keyword needed.
See also
- E01070: 'break' not supported (use stream pipelines with 'head')
- E01071: 'continue' not supported (use stream pipelines with 'filter')
- E01072: 'return' not supported (use return declarations)
- E01073: 'null' not supported (use tri-state semantics)
- E01074: semicolons not needed (indentation-based syntax)
- E01076: 'goto' not supported (use structured control flow)
https://ek9.io/basics.html#objects https://ek9.io/forAI.json#$.excludedFeatures.features[?(@.keyword=="new")]
Examples
Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.
Fails with E01075: 'new' does not exist in EK9 - instantiate types with TypeName() directly
#!ek9 defines module error.e01075.bad defines function //New for simple type instantiation tryNewInstantiation() name <- new String() require name? //New for type with arguments tryNewWithArguments() name <- new String("Steve") require name? //New in assignment to existing variable tryNewInAssignment() name <- String() name: new String("Updated") require name?
Fixed: Call the type to make a value; there is no new
#!ek9 defines module error.e01075.good.fix defines function //New for simple type instantiation tryNewInstantiation() name <- String() require name? //New for type with arguments tryNewWithArguments() name <- String("Steve") require name? //New in assignment to existing variable tryNewInAssignment() name <- String() name: String("Updated") require name?
Fixed: Call the constructor directly: TypeName(...)
#!ek9 defines module error.e01075.good defines function unsetName() <- name as String: String() namedSteve() <- name as String: String("Steve") renamed() <- name as String: String() name: String("Updated")
Questions and answers
These Q&A entries show E01075 and its fix:
Found a problem?
If EK9 reported E01075 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.