gi_dor

컬렉션프레임웍의 인터페이스들은 왜 따로 구현 안할까 ? 본문

First/why ?

컬렉션프레임웍의 인터페이스들은 왜 따로 구현 안할까 ?

기돌 2023. 6. 9. 09:28
728x90

 

 

 

컬렉션 프레임웍의 핵심 인터페이스가 List Set Map Collection  이렇게 있는데

왜 자바 7장에서 나온 인터페이스와 구현 처럼  안하고 책에서는 바로 new 연산자로 객체를 생성할수 있는걸까 ?

interface Fruit {}
class Apple implements Fruit { }

 

public class ArrayListExample {
    public static void main(String[] args) {
   
        ArrayList list1 = new ArrayList(10);

        //list1.add(new Integer(5));
        list1.add(5);
        list1.add(new Integer(4));
        list1.add(new Integer(2));
        list1.add(new Integer(0));
        list1.add(new Integer(1));
        list1.add(new Integer(3));
        System.out.println("list1 = "+ list1);
        
        	}
        }

 

7장 -  인터페이스는 추상메서드 덕분에 new 연산자로 객체를 직접 생성할수가 없다
  인터페이스를  구현한 '클래스'로 객체를 생성할수 있으며
      클래스에는  인터페이스에 선언된 메서드들을 모두 구현해야 new 연산자로 객체를 생성할수 있다.

 

interface List {}
class ArrayList implements List { }

public class Example { 
	public static void main (String[] args){

   	ArrayList<String> list = new ArrayList<>();

    list.add("Hello");
    list.add("World!");
	
    }
}
그냥 갑자기 궁금했다.. 이렇게 안되나 ??

 

 

 

 

JDK 라이브러리 안에 이미 있었네.. 내가 책 제대로 안본거였네 그래서 안된거네..
이미 인터페이스가있고 구현 되어있는데 거기에  인터페이스 선언하고 구현 하니 당연히 안되는 거잖아...

허무하구나

 

728x90

'First > why ?' 카테고리의 다른 글

Math.random( ) ,Math.round( )  (0) 2023.03.06