Skip to content

Instantly share code, notes, and snippets.

View jakubjanecek's full-sized avatar

Jakub Janeček jakubjanecek

  • Prague, Czech Republic
View GitHub Profile
Transaction t1 = new Transaction();
t1.begin();
try {
System.out.println("I am in transaction, safe and sound!");
t1.commit();
} catch (Exception ex) {
t1.rollback();
}
txn {
println("I am in transaction, safe and sound!")
}
def txn(block: => Unit): Unit = {
val transaction = new Transaction
try {
transaction.begin()
block
transaction.commit()
}
int sum = 0;
for (int n : collectionOfNumbers) {
sum += n;
}
val sum = collectionOfNumbers.sum
List<Integer> odds = new ArrayList<Integer>();
for (int n : collectionOfNumbers) {
if (n % 2 == 1) {
odds.add(n);
}
}
val odds = collection.filter(n => n % 2 == 1)
public final class Event {
private final long id;
private final String name;
private final long when;
private final EventSource source;
case class Event(id: Long, name: String, when: Long, source: EventSource)
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();