Many things are outdated and better alternatives exist.
New is used to create new objects. But it’s used carelessly.
In Java you can only reference final fields inside a closure. Here’s my solution*. Continue reading Recursive Closures in Java
Point 11 of the Joel Test asks: “Do new candidates write code during their interview?”
But how do you do that? I find most tips on the internet aren’t really helpful or realistic.
The given implementation for
hashCode is somewhat a mystery. Some misconceptions about it confuse students. I try to explain it. Continue reading Misconceptions about Object.hashCode()
Here’s an implementation of a multiset in Java 8. It uses a
Map<T, Integer> to count how many times an object was inserted (multiplicity). It is not thread-safe, but there’s
synchronizedMultiset(...) and it always knows the current size in
O(1). With the method
asMap() you can get a view of the multiset as a
Map, that will allow modification of the underlying multiset.
The code is on GitHub: github.com/claudemartin/multiset
This started as a simple implementation and is not rather complex. The iterator allows to remove elements during iteration. I tried to write my own
Spliterator, but it wasn’t faster than the default implementaion. Many methods are optimized and I added some set operations for multisets (union, intersect, minus). With
merge(...) you can merge two multisets with any operation.
Yet another side project. But this isn’t usable as it’s not finished and not really tested. The idea is to provide wrapper classes for character sequences so that strings aren’t just copied and some memory can be saved.
The project is hosted here: https://github.com/claudemartin/stringwrappers/
Most tutorials use some recursive Task to calculate a Fibonacci number or something similar. This leads to the false impression that Fork/Join can only handle recursive Tasks (e.g. Divide-And-Conquer). Here’s a very simple example of a non-recursive Task.
Continue reading Fork/Join with non-recursive Task
Here’s an example to show how to implement
compareTo in a decorator.
Continue reading Decorator implementing Comparable