Edited, memorised or added to reading queue

on 23-Aug-2014 (Sat)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

Flashcard 149627104

Tags
#bloch-effective-java-2ed #java #java-generics
Question
Give an example how type safety could be compromised if it was legal to create arrays of parametrized types (but it is not legal).
Answer
  1. You could create an array of lists of strings:
    List<String>[] stringLists = new List<String>[1]; // this part is not legal and wouldn't compile
  2. Because arrays are covariant, you can store the array into a variable of Object[] type and then store an element of type List<Integer> (or really List<anything>) as an element of the original array without causing ArrayStoreException because at runtime List<String> and List<Integer> are simply lists
  3. So, we are in trouble - List<Integer> is stored where the compiler thought it was List<String>

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Sherman
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

John Sherman Cooper - Wikipedia, the free encyclopedia
Yale University Harvard Law SchoolProfessionLawyerReligionBaptistSignatureMilitary serviceService/branchUnited States ArmyYears of service1942–1946RankCaptainUnit15th Corps, U.S. Third ArmyBattles/warsWorld War IIAwardsBronze Star Medal John <span>Sherman Cooper (August 23, 1901 – February 21, 1991) was a politician, jurist, and diplomat from the U.S. state of Kentucky. He served three non-consecutive, partial terms in the United States S




Flashcard 149630657

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to change it to exclude upper bound 4?

for (i <- 1 to 4)
  println("Iteration "+ i)

Answer
Use until method instead of to method:

for (i <- 1 until 4)
  println("Iteration "+ i)


statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630676

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to move the condition to the generator in the loop?

for (file <- filesHere)
  if (file.getName.endsWith(".scala"))
    println(file)

Answer

for (file <- filesHere if file.getName.endsWith(".scala"))
  println(file)


statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630687

Tags
#odersky-programming-in-scala-2ed #scala
Question
What happens if you put multiple <- clauses in for?
Answer
You will get nested loops.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630698

Tags
#odersky-programming-in-scala-2ed #scala
Question
How can you reduce number of semicolons in for loop?
Answer
Use curly braces instead of parentheses - Scala compiler will not infer semicolons in parentheses.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630709

Tags
#odersky-programming-in-scala-2ed #scala
Question
How to introduce a val like variable mid-stream into for clauses?
Answer
Simply x=<whatever>, like val x=<whatever> elsewhere in the code, but without val keyword.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630720

Tags
#odersky-programming-in-scala-2ed #scala
Question
What form of for produces a new collection?
Answer
for clauses yield body

Keyword yield makes body compute elements of the new collection.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







#odersky-programming-in-scala-2ed #scala
One difference from Java that you’ll quickly notice in Scala is that unlike Java, Scala does not require you to catch checked exceptions, or declare them in a throws clause.
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

pdf

cannot see any pdfs




Flashcard 149630747

Tags
#odersky-programming-in-scala-2ed #scala
Question
What will calling f() return?

def f(): Int = try { return 1 } finally { return 2 }

Answer
2

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs







Flashcard 149630762

Tags
#odersky-programming-in-scala-2ed #scala
Question
What will calling g() return?
def g(): Int = try { 1 } finally { 2 }
Answer
1

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

pdf

cannot see any pdfs