Edited, memorised or added to reading queue
Do you want BuboFlash to help you learning these things?
Click here to log in or create user.
Tags
#bloch-effective-java-2ed #equality #java
Question
Suppose we have a class that tries to cooperate with String. What is wrong with it?
public final class CaseInsensitiveString {
private final String s;
@Override public boolean equals(Object o) {
if (o instanceof CaseInsensitiveString)
return s.equalsIgnoreCase(((CaseInsensitiveString) o).s);
if (o instanceof String)
return s.equalsIgnoreCase((String) o);
return false;
}
// rest of the code
}
Answer
It violates symmetry of equality - "BlaBla".equals(whatever) will do case-sensitive comparison, even if whatever is CaseInsensitiveString (in which case the result is false)
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#bonds #duration #finance
Question
[another name of DV01, not the meaning of the abbreviation DV01] or DV01 is the change in price in dollars, not in percentage.
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Parent (intermediate) annotation
Open itDollar duration or DV01 is the change in price in dollars, not in percentage.Original toplevel document
Bond duration - Wikipedia, the free encyclopediae point change in yield)
or
($ per 1 basis point change in yield)
The DV01 is analogous to the delta in derivative pricing (The Greeks) – it is the ratio of a price change in output (dollars) to unit change in input (a basis point of yield). <span>Dollar duration or DV01 is the change in price in dollars, not in percentage. It gives the dollar variation in a bond's value per unit change in the yield. It is often measured per 1 basis point - DV01 is short for "dollar value of an 01" (or 1 basis poi
#odersky-programming-in-scala-2ed #scala
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
the first element in a Scala array named steps is steps(0), not steps[0], as in Java
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What does
to stand for in this example?
for (i <- 0 to 2)
print(greetStrings(i))
Answer
a method call (0).to(2)
if a method takes only one parameter, you can call it without a dot or parentheses.
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
You cannot write “println 10”, but you can write “Console println 10”.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What does + really stand for in 2 + 3?
Answer
it is a method call: (2).+(3)
method is named "+"
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
if greetStrings is an array, greetStrings(i) gets transformed into
Answer
greetStrings.apply(i)
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
Accessing an element of an array in Scala is simply a method call like any other. This principle is not restricted to arrays: any application of an object to some arguments in parentheses will be transformed to an apply() method call. Of course this will compile only if that type of object actually defines an apply method.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
When an assignment is made to a variable to which parentheses and one or more arguments have been applied, the compiler will transform that into an invocation of an update method that takes the arguments in parentheses as well as the object to the right of the equals sign.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What will greetStrings(0) = "Hello" be transformed into?
Answer
greetStrings.update(0, "Hello")
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What method are you calling here and where is it defined?
val numNames = Array("zero", "one", "two")
Answer
a factory method apply which takes variable number of argumetns and is defined on Array companion object
the code gets transformed to
val numNames2 = Array.apply("zero", "one", "two")
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What does the cons expression, e.g. 1::twoThree, gets translated to (in terms of method calls)?
What rule is used?
Answer
twoThree.::(1)
if a method's name used in operator notation ends with colon, it is called on the right operand
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
to instantiate a new tuple that holds some objects, just [...].
Answer
place the objects in parentheses, separated by commas
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
Both mutable and immutable sets offer a + method, but their behavior differs. Whereas a mutable set will add the element to itself, an immutable set will create and return a new set with the element added.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Although mutable sets offer an actual += method, immutable sets do not. In this case, jetSet += "Lear", is essentially [...]
Answer
a shorthand for jetSet = jetSet + "Lear"
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
When you add a key-value pair to a map: treasureMap += (2 -> "Dig.") , what is 1 -> "Dig." really?
Answer
It is a method call (1).->("Dig") which returns a tuple containing key and value
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
Where you’d say “public” in Java, you simply say nothing in Scala. Public is Scala’s default access level.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
method parameters in Scala is that they are vals, not vars
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Whenever you [...], its result type will definitely be Unit. This is true no matter what the body contains, because the Scala compiler can convert any type to Unit.
Answer
leave off the equals sign before the body of a function
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
a semicolon is required if you write multiple statements on a single line
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
When [...], it is called that class’s companion object.
Answer
a singleton object shares the same name with a class
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What is the class that has companion object called?
Answer
companion class of that object
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Where a companion class and its companion objects have to be defined?
Answer
in the same source file
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
What is special about access control between companion object and companion class?
Answer
they can access each other's private members
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Article 149629895#odersky-programming-in-scala-2ed #p109 #scala
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins with a word that cannot start a statement.The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
Tags
#odersky-programming-in-scala-2ed #scala
Question
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
- The line in question ends [...].
- The next line begins with a word that cannot start a statement.
- The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
Answer
in a word that would not be legal as the end of a statement, such as a period or an infix operator
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Open itIn short, a line ending is treated as a semicolon unless one of the following conditions is true:
The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins with a word that cannot start a statement.The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.&#
Tags
#odersky-programming-in-scala-2ed #scala
Question
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
- The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.
- The next line begins [...].
- The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
Answer
with a word that cannot start a statement
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Open itrt, a line ending is treated as a semicolon unless one of the following conditions is true:
The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins <span>with a word that cannot start a statement.The line ends while inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
<span><body><html>
Tags
#odersky-programming-in-scala-2ed #scala
Question
In short, a line ending is treated as a semicolon unless one of the following conditions is true:
- The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.
- The next line begins with a word that cannot start a statement.
- The line ends while [...].
Answer
inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Open itfollowing conditions is true:
The line in question ends in a word that would not be legal as the end of a statement, such as a period or an infix operator.The next line begins with a word that cannot start a statement.The line ends while <span>inside parentheses (...) or brackets [...], because these cannot contain multiple statements anyway.
<span><body><html>
#odersky-programming-in-scala-2ed #scala
Any standalone object with a main method of the proper signature can be used as the entry point into an application.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
Scala implicitly imports members of packages java.lang and scala, as well as the members of a singleton object named Predef, into every Scala source file.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
How to express s.indexOf(’o’, 5) in operator notation?
Answer
s indexOf ('o', 5)
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
The only identifiers that can be used as prefix operators are +, -, !, and ~.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Scala will transform the expression -2.0 into [...]
Answer
the method invocation (2.0).unary_-
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
if you define a method unary_* and then try to call it on object in prefix notation *p, how will Scala parse it and why?
Answer
*.p because * is not one of the four names allowed for prefix methods
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Postfix operators are methods that [what's their signature and how are they invoked?].
Answer
take no arguments, when they are invoked without a dot and parentheses
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
How does scala decide on precedence when methods are used in operator notation, like 2 + 2 * 7 ? What is Scala's default rule here?
Answer
Scala decides precedence based on the first character of the methods used in operator notation (this rule has exceptions). If the method name starts with a *, for example, it will have a higher precedence than a method that starts with a +.
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
One exception to the method / operator precedence rule based on first character in the method name is this: If an operator ends in an equals character (=), and the operator is not one of the comparison operators <=, >=, ==, or !=, then the precedence of the operator is the same as that of simple assignment (=).
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
x *= y + 1
means the same as:
x *= (y + 1)
because *= is classified as an assignment operator whose precedence is lower than +, even though the operator’s first character is *, which would suggest a precedence higher than +.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Article 149630089#odersky-programming-in-scala-2ed #p136 #scala
When multiple operators of the same precedence appear side by side in an expression, the associativity of the operators determines the way operators are grouped.
Tags
#odersky-programming-in-scala-2ed #scala
Question
When [...], the associativity of the operators determines the way operators are grouped.
Answer
multiple operators of the same precedence appear side by side in an expression
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Open itWhen multiple operators of the same precedence appear side by side in an expression, the associativity of the operators determines the way operators are grouped.
Tags
#odersky-programming-in-scala-2ed #scala
Question
When multiple operators of the same precedence appear side by side in an expression, the [...] of the operators determines the way operators are grouped.
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Open itWhen multiple operators of the same precedence appear side by side in an expression, the associativity of the operators determines the way operators are grouped.
Tags
#odersky-programming-in-scala-2ed #scala
Question
The associativity of an operator in Scala is determined by [...].
Answer
its last character
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
any method that ends in a ‘:’ character (e.g. cons) is invoked on [which operand is the receiver and which is the argument of the method invocation?]. Methods that end in any other character are the other way around.
Answer
its right operand, passing in the left operand
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
No matter what associativity an operator has, however, its operands are always evaluated [in what order?].
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
In Java, classes have constructors, which can take parameters, whereas in Scala, classes can take parameters directly.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Question
Where will Scala compiler put the println() code?
class Rational(n: Int, d: Int) {
println("Created "+ n +"/"+ d)
}
Answer
Into the primary constructor
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Question
How can we forbid creating rationals where denominator equals 0?
class Rational(n: Int, d: Int) {
println("Created "+ n +"/"+ d)
}
Answer
Add preconditon using
require method that throws an exception if it receives
false:
class Rational(n: Int, d: Int) {
require(d != 0)
println("Created "+ n +"/"+ d)
}
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Why won't this compile?
class Rational(n: Int, d: Int) { // This won’t compile
require(d != 0)
override def toString = n +"/"+ d
def add(that: Rational): Rational =
new Rational(n * that.d + that.n * d, d * that.d)
}
Answer
Because n and d can only be accessed in methods for this object - they seem to be captured like in closure for toString. They are not fields / members though
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
In Scala, constructors other than the primary constructor are called
Answer
auxiliary constructors
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
Auxiliary constructors in Scala start with [...].
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|
#odersky-programming-in-scala-2ed #scala
Identifiers in user programs should not contain ‘$’ characters, even though it will compile; if they do this might lead to name clashes with identifiers generated by the Scala compiler.
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
#odersky-programming-in-scala-2ed #scala
the identifier :-> would be represented internally as $colon$minus$greater
|
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Tags
#odersky-programming-in-scala-2ed #scala
Question
How to call Thread.yield() in Scala, where yield is a reserved word?
Answer
Thread.`yield`()
string enclosed in backticks becomes an identifier, no matter how arbitrary it is.
status | not learned | | measured difficulty | 37% [default] | | last interval [days] | |
---|
repetition number in this series | 0 | | memorised on | | | scheduled repetition | |
---|
scheduled repetition interval | | | last repetition or drill | | | | |
---|