Sweet.apex

  • Docs
  • Tutorials
Docs Menu
  • Sweet.apex Core
    • Transpilation
    • Grammar
    • Command
    • Config
  • Features
    • Action
    • Apex Doc
    • Array Creation
    • Aspect
    • Cast
    • Default Value
    • Enum
    • File
    • Function
    • Identity
    • Injection
    • Lambda
    • Log
    • Mod
    • Not Null
    • Operator
    • Optional
    • Reflection
    • Rethrow
    • Switch
    • Template String
    • Template
    • Script
    • Tagged String
    • Annotation
    • Nullable
    • Var
    • Val
    • Map Access
    • Constructor
    • Transaction
    • Destructure
    • Import Static
    • Pipeline
    • Varargs
    • Patch
    • Import As
  • Plugin Development
    • Feature
    • Test Case

Array Creation Guide

Array Creation

Feature Overview

This feature enables simple creation of arrays/lists and maps.

Prerequisite

None

Sweet Apex Example

public class ArrayCreation {
    public static void run(Object o) {
    }

    public static void main() {
        Map m = new Map{ 'a': 2, };
        List l = new List{ 'a', };

        Map m1 = { 'a' => 2 };
        List l1 = { 'a' };

        Object m2 = { 'a' => 2 };
        Object l2 = { 'a' };

        Map m3 = { 'a' => { 'b' => 2 } };
        List l3 = { { 'a' } };

        run({ 'a' => 2 });
        run({ 'a' });
    }
}

Transpiled Apex

public class ArrayCreation {
    public static void run(Object o) {
    }
    public static void main() {
        Map m = new Map{ 'a' => 2 };
        List l = new List{ 'a' };

        Map m1 = new Map{ 'a' => 2 };
        List l1 = new List{ 'a' };

        Object m2 = new Map{ 'a' => 2 };
        Object l2 = new List{ 'a' };

        Map m3 = new Map{ 'a' => new Map{ 'b' => 2 } };
        List l3 = new List{ new List{ 'a' } };
        run(new Map{ 'a' => 2 });
        run(new List{ 'a' });
    }
}

Usage

When enabled, this feature helps you to complete the array creation.

Contribute on Github! Edit this section.