[JAVA] java.lang패키지와 유용한 클래스 - Wrapper 클래스, Number 클래스

선영·2022년 8월 28일
post-thumbnail

래퍼(wrapper) 클래스

  • 8개의 기본형을 객체로 다뤄야할 때 사용하는 클래스.
	public final class Integer extends Number implements Comparable {
    	...
        private int value;  //기본형(int)을 감싸고 있음. 
    }    


Number 클래스

  • 모든 숫자 래퍼 클래스의 조상
  public abstract class Number implements java.io.Serializable {
  	public abstract int intValue(); 
    public abstract long longValue();
    public abstract float floatValue(); 
    public abstract double doubleValue(); 
    
    public byte byteValue() {
    	return (byte)intValue();
    }
    
    public short shortValue() {
    	return (short)intValue(); 
    }
  }  

0개의 댓글