Skip to content

Instantly share code, notes, and snippets.

@iande
iande / Badness.java
Created April 17, 2012 20:51
Why instanceof Is the Devil.
public class Triangle {
public int width;
public int height;
}
public class Rectangle {
public int width;
public int height;
}
@iande
iande / 01_without_boxing.java
Created April 19, 2012 13:20
Boxing and Unboxing example
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(new Integer(10));
myList.add(new Integer(11));
myList.add(new Integer(12));
@iande
iande / Box.java
Created May 9, 2012 14:34
Why generic type checking is slightly different...
public class Box<T> {
private T whatsInTheBox;
// Creates a new box that holds nothing of value
public Box() { this(null); }
// Creates a new box that holds the given T instance.
public Box(T store) {
this.set(store);
}
@iande
iande / NumberBox.java
Created May 11, 2012 20:40
Bounded Type Parameters
// The bounded type parameter dictates the kinds of Box instances we can create.
public class NumberBox<T extends Number> {
private T _number;
public NumberBox() { this(null); }
public NumberBox(T toStore) {
set(toStore);
}
public T get() { return _number; }

Keybase proof

I hereby claim:

  • I am iande on github.
  • I am iande (https://keybase.io/iande) on keybase.
  • I have a public key ASAAZLXxLfI56JPzKX02tjCdOJwekL22WGsEiHzJyTU1LQo

To claim this, I am signing this object: