此代码编译:
def wtf(arg: Any) = {
arg match {
case Nil => "Nil was passed to arg"
case List() => "List() was passed to arg"
case _ =>"otherwise"
}
}
Run Code Online (Sandbox Code Playgroud)
但是这个没有:
def wtf(arg: Any) = {
arg match {
case List() => "List() was passed to arg"
case Nil => "Nil was passed to arg"
case _ =>"otherwise"
}
}
Run Code Online (Sandbox Code Playgroud)
行 情况Nil => ...被标记为无法访问的代码.为什么,在第一种情况下,行案例List()=> ...没有标记相同的错误?
天真的困惑:
var arr1 = new Array();
var arr2 = Object.create(Array.prototype);
//Inserting elements in "both arrays"
arr1[0] =0;
arr1[9] =9;
arr2[0] =0;
arr2[9] =9;
arr1.push(10);
arr2.push(10);
console.log(arr1.length); // prints 11
console.log(arr2.length); // prints 1
Run Code Online (Sandbox Code Playgroud)
两个对象都继承了Array.prototype,但它们与[]运算符的行为不同.为什么?