This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Transaction t1 = new Transaction(); | |
t1.begin(); | |
try { | |
System.out.println("I am in transaction, safe and sound!"); | |
t1.commit(); | |
} catch (Exception ex) { | |
t1.rollback(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
txn { | |
println("I am in transaction, safe and sound!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def txn(block: => Unit): Unit = { | |
val transaction = new Transaction | |
try { | |
transaction.begin() | |
block | |
transaction.commit() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int sum = 0; | |
for (int n : collectionOfNumbers) { | |
sum += n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val sum = collectionOfNumbers.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Integer> odds = new ArrayList<Integer>(); | |
for (int n : collectionOfNumbers) { | |
if (n % 2 == 1) { | |
odds.add(n); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val odds = collection.filter(n => n % 2 == 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Event { | |
private final long id; | |
private final String name; | |
private final long when; | |
private final EventSource source; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Event(id: Long, name: String, when: Long, source: EventSource) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static int genericSize(Object obj) { | |
if (obj instanceof String) { | |
String s = (String) obj; | |
return s.length(); | |
} else if (obj instanceof int[]) { | |
int[] a = (int[]) obj; | |
return a.length; | |
} else if (obj instanceof List) { | |
List l = (List) obj; | |
return l.size(); |
OlderNewer