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

Import Static Guide

Import Static

Feature Overview

This feature imports static fields and methods from classes and enables them to be used without prefixing class names.

Prerequisite

None

Sweet Apex Example

import static Math;

public class ImportStaticDemo {
    public static void main() {
        Double d = PI;

        Integer result = abs(-1);
    }
}

Transpiled Apex

public class ImportStaticDemo {
    public static void main() {
        Double d = Math.PI;

        Integer result = Math.abs(-1);
    }
}

Usage

Static importing depends on type checking. Should type checking go wrong, static importing will fail.

Contribute on Github! Edit this section.