Skip to content

Commit

Permalink
Add list constant and map constant examples
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Jul 14, 2023
1 parent b5249c0 commit e833861
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/const-and-final/const_and_final.bal
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import ballerina/io;
const MAX_VALUE = 1000;
const URL = "https://ballerina.io";

// Map and list can be declared as constant.
const HTTP_OK = {httpCode: 200, message: "OK"};
const ERROR_CODES = [200, 202, 400];

// The value for variable `msg` 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
2 changes: 1 addition & 1 deletion 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
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

0 comments on commit e833861

Please sign in to comment.