Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2201.8.x] Update const BBE #4713

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions examples/const-and-final/const_and_final.bal
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import ballerina/io;

const int MAX_VALUE = 1000;

// Constants can be defined without the type. Then, the type is inferred from the right-hand side.
const MAX_VALUE = 1000;
const URL = "https://ballerina.io";

// The value for variable `msg` can only be assigned once.
// Mapping and list constants can also be defined.
const HTTP_OK = {httpCode: 200, message: "OK"};
const ERROR_CODES = [200, 202, 400];

// The value for the `msg` variable can only be assigned once.
final string msg = loadMessage();

public function main() {
io:println(MAX_VALUE);
io:println(URL);
io:println(HTTP_OK);
io:println(ERROR_CODES);
io:println(msg);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/const-and-final/const_and_final.metatags
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
description: This BBE demonstrates how const and final values are used in Ballerina.
keywords: ballerina, ballerina by example, bbe, const, final
description: This BBE demonstrates how `const` and `final` values are used in Ballerina.
keywords: ballerina, ballerina by example, bbe, const, final, map const, list const
2 changes: 2 additions & 0 deletions examples/const-and-final/const_and_final.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
$ bal run const_and_final
1000
https://ballerina.io
{"httpCode":200,"message":"OK"}
[200,202,400]
Hello World
Loading