Ownership
fn main() {
let nums = vec![2, 4, 6];
let nums2 = nums;
package main | |
import ( | |
"fmt" | |
"strings" | |
"syscall" | |
) | |
func main() { |
package main | |
import ( | |
"fmt" | |
"strings" | |
"syscall" | |
) | |
func main() { |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"net" | |
"strconv" | |
"strings" | |
) |
Assume you have a couple of classes,
case class Person(name: String, age: Int)
case class Employee(person: Person, salary: Double)
Lets say for some reason,
save(person)
and save(employee)
, andTypically, you can't use a 'new' operator on a generic type. This is because of type erasure.
scala> def create[T] = new T
<console>:7: error: class type required but T found
def create[T] = new T
^
Scala gives a way of getting around this problem, with the Manifest
class.
scala> def create[T](implicit m:Manifest[T]) = m.erasure.newInstance
I hereby claim:
To claim this, I am signing this object:
use std::cmp::max; | |
fn largest2(arr: [i32; 5]) -> i32 { | |
arr.iter().fold(0, |num, &x| { | |
max(num, x) | |
}) | |
} | |
fn largest3(arr: [i32; 5]) -> i32 { | |
arr.iter().fold(0, max) // Do Not compile! |
10 | |
14 | |
9 3 | |
2 5 | |
6 5 | |
9 8 | |
0 3 | |
4 7 | |
2 1 | |
0 6 |