본문 바로가기

분류 전체보기122

래퍼 클래스 package org.example; public class Main5 { public static void main(String[] args) { //boxing Integer integer1 = Integer.valueOf(10); Integer integer2 = Integer.valueOf(20); //unboxing int int1 = integer1; //intValue 를 적어도 되고 안적어도 된다. int int2 = integer2.intValue(); System.out.println(integer1); System.out.println(integer2); System.out.println(int1); System.out.println(int2); } } 자료형 값을 boxing 하면 .. 2024. 1. 31.
clone 메서드 package org.example; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; import lombok.ToString; @Setter @Getter @ToString @AllArgsConstructor public class Point { private int xpos; private int ypos; @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } // public Point(int xpos, int ypos) { // this.xpos = xpos; // this.ypos = ypo.. 2024. 1. 31.
Object class finalize 메소드를 사용 하여 오버라이딩 할 수 있다. package org.example; public class Person { private String name; public Person(String name) { this.name = name; } @Override protected void finalize() throws Throwable { super.finalize(); System.out.println("destroyed" + name); } } package org.example; public class Main { public static void main(String[] args) { Person p1 = new Person("park"); Person p2 = new Pers.. 2024. 1. 31.
JAVA 의 메모리 모델 ● 메소드 영역 바이트코드와 static 변수가 할당되는 공간 ※이 영역에 저장된 내용은 프로그램 종료 시 소멸된다. ● 스택 영역 지역변수 매개변수 할당되는 영역 ※이 영역에 저장된 변수는 해당 변수가 선언된 메소드 종료 시 소멸된다. ● 힙 영역 인스턴스가 저장되는 영역이다. ※가비지 컬렉션의 대상이 되는 영역이다. 2024. 1. 31.