1. /*
  2. * @(#)Number.java 1.29 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. /**
  9. * The abstract class <code>Number</code> is the superclass of classes
  10. * <code>BigDecimal</code>, <code>BigInteger</code>,
  11. * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
  12. * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
  13. * <p>
  14. * Subclasses of <code>Number</code> must provide methods to convert
  15. * the represented numeric value to <code>byte</code>, <code>double</code>,
  16. * <code>float</code>, <code>int</code>, <code>long</code>, and
  17. * <code>short</code>.
  18. *
  19. * @author Lee Boynton
  20. * @author Arthur van Hoff
  21. * @version 1.29, 12/19/03
  22. * @see java.lang.Byte
  23. * @see java.lang.Double
  24. * @see java.lang.Float
  25. * @see java.lang.Integer
  26. * @see java.lang.Long
  27. * @see java.lang.Short
  28. * @since JDK1.0
  29. */
  30. public abstract class Number implements java.io.Serializable {
  31. /**
  32. * Returns the value of the specified number as an <code>int</code>.
  33. * This may involve rounding or truncation.
  34. *
  35. * @return the numeric value represented by this object after conversion
  36. * to type <code>int</code>.
  37. */
  38. public abstract int intValue();
  39. /**
  40. * Returns the value of the specified number as a <code>long</code>.
  41. * This may involve rounding or truncation.
  42. *
  43. * @return the numeric value represented by this object after conversion
  44. * to type <code>long</code>.
  45. */
  46. public abstract long longValue();
  47. /**
  48. * Returns the value of the specified number as a <code>float</code>.
  49. * This may involve rounding.
  50. *
  51. * @return the numeric value represented by this object after conversion
  52. * to type <code>float</code>.
  53. */
  54. public abstract float floatValue();
  55. /**
  56. * Returns the value of the specified number as a <code>double</code>.
  57. * This may involve rounding.
  58. *
  59. * @return the numeric value represented by this object after conversion
  60. * to type <code>double</code>.
  61. */
  62. public abstract double doubleValue();
  63. /**
  64. * Returns the value of the specified number as a <code>byte</code>.
  65. * This may involve rounding or truncation.
  66. *
  67. * @return the numeric value represented by this object after conversion
  68. * to type <code>byte</code>.
  69. * @since JDK1.1
  70. */
  71. public byte byteValue() {
  72. return (byte)intValue();
  73. }
  74. /**
  75. * Returns the value of the specified number as a <code>short</code>.
  76. * This may involve rounding or truncation.
  77. *
  78. * @return the numeric value represented by this object after conversion
  79. * to type <code>short</code>.
  80. * @since JDK1.1
  81. */
  82. public short shortValue() {
  83. return (short)intValue();
  84. }
  85. /** use serialVersionUID from JDK 1.0.2 for interoperability */
  86. private static final long serialVersionUID = -8742448824652078965L;
  87. }