This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //mutable | |
| int x = 1; | |
| var y = new Dictionary<string, string>(); | |
| //immutable | |
| const int a = 1; | |
| const var b = new Dictionary<string, string>(); // Won't compile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let x = 123; | |
| let mut y = "Hello"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final Person frank = new Person("Frank", "Walker"); | |
| frank.setFirstName("Bob"); | |
| System.out.println(frank.getFirstName()) // prints "Bob" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let num = if input > 0 then true else false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def factorial(n: Int) : Int = { | |
| @tailrec | |
| def factorialWithAccumulator(acc: Int, n: Int) : Int = { | |
| if (number == 1) acc | |
| else factorialWithAccumulator(accumulator * n, n - 1) | |
| } | |
| factorialWithAccumulator(1, n) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String constructionFirm = person.getResidence().getAddress().getConstructionFirm(); | |
| //Can't do this because residence, address or constructionFirm could be null. | |
| String constructionFirm = null; | |
| if(person != null){ | |
| Residence residence = person.getResidence(); | |
| if(residence != null){ | |
| Address address = residence.getAddress(); | |
| if(address != null){ | |
| constructionFirm = adress.getConstructionFirm(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def constructionFirm = person?.residence?.address?.constructionFirm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| constructionFirm = person&.residence&.address&.constructionFirm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| personOption |> Option.bind (fun p -> p.residence) | |
| |> Option.bind (fun r -> r.address) | |
| |> Option.map (fun a -> a.constructionFirm) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Optional<String> firm = personOption | |
| .flatMap(Person::getResidence) | |
| .flatMap(Residence::getAddress) | |
| .map(Address::getConstructionFirm) |
OlderNewer