Skip to content

Instantly share code, notes, and snippets.

@karanmalhi
Created June 20, 2011 15:21
Show Gist options
  • Save karanmalhi/1035813 to your computer and use it in GitHub Desktop.
Save karanmalhi/1035813 to your computer and use it in GitHub Desktop.
Example of an advanced enum
package com.lq;
public enum CreditCardType {
VISA("111-22-3333") {
@Override
public boolean isValid() {
System.out.println("Validating a " + this.name());
return false;
}
},
MASTERCARD("0123456789") {
@Override
public boolean isValid() {
System.out.println("Validating a " + this.name());
return false;
}
},
AMEX("37957893457834") {
@Override
public boolean isValid() {
System.out.println("Validating a " + this.name());
return false;
}
};
private String number;
private CreditCardType(String number) {
this.number = number;
}
public abstract boolean isValid(); // write card specific validation
// LUND's formula
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment