How would you code an efficient Circular Buffer in Java or C#?

I would use an array of T, a head and tail pointer, and add and get methods. Like: (Bug hunting is left to the user) // Hijack these for simplicity import java.nio.BufferOverflowException; import java.nio.BufferUnderflowException; public class CircularBuffer<T> { private T[] buffer; private int tail; private int head; @SuppressWarnings(“unchecked”) public CircularBuffer(int n) { buffer = (T[]) … Read more

Nested Java enum definition – does declaring as static make a difference? [duplicate]

No, it makes no difference. However the reason is not because it is a member declaration inside an interface, as Jon says. The real reason is according to language spec (8.9) that Nested enum types are implicitly static. It is permissable to explicitly declare a nested enum type to be static. At the following example … Read more