인터페이스 와 추상 인터페이스 (interface & abstract interface)

1897 단어 springhtml
이전 에는 Spring 의 applicationContext 인 터 페 이 스 를 사용 하여 제공 하 는 방법 을 보고 jar 가방 을 열 었 습 니 다. 보 이 는 정 보 는 다음 과 같 습 니 다.
public abstract interface org.springframework.context.ApplicationContext extends ... {  
    public abstract org.springframework.context.ApplicationContext getParent();  
    ...  
  
} 

 인터페이스 앞 에 abstract 가 있 는 것 을 발견 하면 추상 인터페이스 (abstract interface) 가 있 습 니 다. 인터페이스 가 모두 추상 적 이지 않 습 니까? 이렇게 쓰 면 무슨 특별한 의미 가 있 는 지 궁금 합 니 다. 인터넷 에 접속 하여 일부 자 료 를 조회 하고, 어떤 네티즌 들 은 유명한 자바 책 에 쓴 인터페이스 에 관 한 논술 을 붙 였 다. 자바 in a nutshell 에서... “All methods of an interface are implicitly abstract, even if the abstract modifier is omitted.” thinking in 자바 에서... “the abstract keyword, which allows you to create one or more methods in a class that have no definitions—you provide part of the interface without providing a corresponding implementation, which is created by inheritors. The interface keyword produces a completely abstract class, one that provides no implementation at all.” 그래서 결론 은 abstract interface 는 interface 이 고 둘 은 전혀 다 르 지 않다 는 것 이다. 그런데 왜 그들 은 그렇게 쓰 려 고 합 니까? 쓸데없는 짓 이 아 닙 니까?jar 가방 에 포 함 된 abstract 를 자동 으로 추가 한 것 이 아 닙 니까? 저 는 소스 코드 를 찾 았 습 니 다. 과연 소스 코드 에는 abstract 가 없습니다.
 
public interface ApplicationContext extends ListableBeanFactory, HierarchicalBeanFactory,  
        MessageSource, ApplicationEventPublisher, ResourcePatternResolver {  
  
    ApplicationContext getParent();  
    ...  
}

 그래서 결론 은: interface 는 abstract 를 포함 하고 있 습 니 다. interface 는 abstract interface 와 같은 역할 을 합 니 다. 다만 abstract interface 는 더욱 완전한 표현 일 뿐 입 니 다.
원문 발췌:
http://www.cnblogs.com/sunwei2012/archive/2010/12/10/1902100.html

좋은 웹페이지 즐겨찾기