blog

Sunday, January 23, 2011

enum type with constant-specific method implementations


public enum Operation {
PLUS { double apply(double x, double y) {return x + y;} },
MINUS { double apply(double x, double y) {return x - y;} },
TIMES { double apply(double x, double y) {return x * y;} },
DIVIDE { double apply(double x, double y) {return x / y;} };

abstract double apply(double x, double y);
}


References
- Effective Java 2nd Edition
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Labels: enum, java
Newer Post Older Post Home

Blog Archive

  • ▼  2011 (11)
    • ►  October (1)
    • ►  September (2)
    • ►  March (2)
    • ►  February (1)
    • ▼  January (5)
      • enum type with constant-specific method implementa...
      • Простые Движения
      • "run" batch file to include all jar's lib folder
      • Microsoft SQL Server 2005 XA
      • Я Твоя Не Первая
  • ►  2010 (3)
    • ►  December (1)
    • ►  October (1)
    • ►  June (1)
  • ►  2009 (2)
    • ►  August (2)
  • ►  2007 (3)
    • ►  October (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2006 (8)
    • ►  December (4)
    • ►  November (1)
    • ►  October (2)
    • ►  January (1)
  • ►  2005 (28)
    • ►  December (13)
    • ►  November (2)
    • ►  October (1)
    • ►  September (4)
    • ►  August (4)
    • ►  July (4)
  • ►  2004 (1)
    • ►  November (1)
  • ►  2003 (1)
    • ►  July (1)
Watermark theme. Powered by Blogger.