E01075: 'new' does not exist in EK9 - instantiate types with TypeName() directly

Category: E01xxx Parsing and excluded constructs · Reported in phase: SYMBOL_DEFINITION · Classification: NEW_NOT_SUPPORTED · All error codes

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()
      assert name?

    //New for type with arguments
    tryNewWithArguments()
      name <- new String("Steve")
      assert name?

    //New in assignment to existing variable
    tryNewInAssignment()
      name <- String()
      name: new String("Updated")
      assert 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: