import ballerina/io;
function getValue () returns (any) {
    string name = "cat";
    return name;
}function main (string[] args) {
    any a = 5;
    io:println(a);
    int intVal = check <int> a;
    io:println(intVal + 10);
    int[] ia = [1, 3, 5, 6];
    any ar = ia;
    io:println(ar);    io:println(getValue());
}

Any Type

The 'any' data type is the root of the Ballerina data types. It can represent a variable of any data type. When you do not have prior knowledge of the data type of your variable, you can assign it the type 'any'. Values of these variables can come from dynamic content such as request and response messages and user input. The 'any' type allows you to skip compile-time data type checks.

import ballerina/io;
function getValue () returns (any) {
    string name = "cat";
    return name;
}

This function returns a value of type ‘any’.

function main (string[] args) {
    any a = 5;
    io:println(a);

The variable named ‘a’ of type ‘any’ holds a value of type ‘int’ in this case.

    int intVal = check <int> a;
    io:println(intVal + 10);

First, you should cast the variable of type ‘any’ to the type you want (e.g., int). You can learn more about type casting in the next section.

    int[] ia = [1, 3, 5, 6];
    any ar = ia;
    io:println(ar);

In Ballerina, a variable of type ‘any’ can hold values of any data type.

    io:println(getValue());
}
$ ballerina run any-type.bal
5
15
[1, 3, 5, 6]
cat