The pared down version of "Scala: The Swiss Army Language" encompassing just the parts that could get you into trouble on day 1 of a dive into an existing, mature Scala codebase.
res1: String = Hello, Scala!!! public abstract class Function1<T, R> { public R apply(T t); } final Function1<String, String> f = new Function1<String, String>() { public String apply(String s) { return s + "!!!"; } }; f.apply(”Hello, Scala");
operator length should be enabled by making the implicit value scala.language.postfixOps visible. This can be achieved by adding the import clause 'import scala.language.postfixOps'
operator length should be enabled by making the implicit value scala.language.postfixOps visible. This can be achieved by adding the import clause 'import scala.language.postfixOps'
endIndex: Int, focus: Int) extends AbstractSeq[A] with IndexedSeq[A] with GenericTraversableTemplate[A, Vector] with IndexedSeqLike[A, Vector[A]] with VectorPointer[A @uncheckedVariance] with Serializable with CustomParallelizable[A, ParVector[A]] sealed abstract class List[+A] extends AbstractSeq[A] with LinearSeq[A] with Product with GenericTraversableTemplate[A, List] with LinearSeqOptimized[A, List[A]] with Serializable { class ListMap[A, +B] extends AbstractMap[A, B] with Map[A, B] with MapLike[A, B, ListMap[A, B]] with Serializable {
int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public String toString() { return "Person(name=" + name + ", age=" + age + ")"; }
private final int age; public Person(final String name, final Integer age) { if(age == null || name == null) throw new NullPointerException(); this.name = name; this.age = age; } public String name() { return name; } public int age() { return age; } public Person copy(String name, Integer age) { return new Person(name == null ? this.name : name, age == null ? this.age : age); } public Person copy(String name) { return new Person(name == null ? this.name : name, this.age); } public Person copy(Integer age) { return new Person(this.name, age == null ? this.age : age); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Person other = (Person) obj; if (age != other.age) { return false; } if (name == null && other.name != null) { return false; } else if (!name.equals(other.name)) { return false; } return true; } @Override public String toString() { return "Person(name=" + name + ", age=" + age + ")"; } public static Person apply(String name, int age) { return new Person(name, age); } } case class Person(name: String, age: Int)
1 case _ => n * factorial(n-1) } TAIL-CALL RECURSION <console>:11: error: could not optimize @tailrec annotated method factorial: it contains a recursive call not in tail position case _ => n * factorial(n-1)
(head, tail) | } <console>:8: warning: match may not be exhaustive. It would fail on the following input: Nil List(1,2,3,4) match { ^ res0: (Int, List[Int]) = (1,List(2, 3, 4)) PATTERN MATCHING
def f(implicit i: Int) = i + 5 f: (implicit i: Int)Int scala> f <console>:9: error: could not find implicit value for parameter i: Int f ^ scala> implicit val x = 5 x: Int = 5 scala> f res3: Int = 10 IMPLICIT VALUES