Wednesday, December 14, 2011

Various index techniques

enum Coin {
    penny(1), nickel(5), dime(10), quarter(25)
    private final int value
    Coin(int value) { this.value = value }
    public int value() { return value }
}
assert 'penny' == Coin.penny.toString()
assert 1 == Coin.penny.value

Map Coin2 = [penny:1, nickel:5, dime:10, quarter:25]
assert 1 == Coin2.penny

List Coin3 = ['penny', 'nickel']
assert 1 == Coin3.indexOf('nickel')

No comments:

Post a Comment