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

Varargs Guide

Varargs

Feature Overview

This feature enables varargs parameters in methods.

Prerequisite

None.

Sweet Apex Example

public class VarargsDemo {
    private static void run(Integer num, String ...args) {
    }

    public static void main() {
        run(10, 'a', 'b');
    }
}

Transpiled Apex

public class VarargsDemo {
    private static void run(Integer num, List args) {
    }
    public static void main() {
        run(10, new List{ 'a', 'b' });
    }
}

Usage

The var-args parameter should be the last parameter in the method and the method should contain at most one var-args parameter. Besides, overloading methods with var-args may cause ambiguity.

Contribute on Github! Edit this section.