Info
Generic 타입
일반적인 클래스를 Object로 선언하면 사용할 때 구체 클래스 타입으로 형변환을 해야하며, 이때 실수를 하게되면 run time에 가서야 detect를 할 수 있다. 그래서 generic 타입을 사용함
네이밍
E - Element (used extensively by the Java Collections Framework
K - Key
N - Number
T - Type
V - Value
S, U, V etc. - 2nd, 3rd, 4th types
제네릭 메소드
보통 in-param에서는 extends를 사용하고 out-param에서는 super을 사용하고, in-out param에서는 wildcard를 사용하지 않는 것이 좋다. (특히 out-param에서 extends를 사용하는 실수를 하지 마라)
제네릭 타입<?>: Unbounded Wildcards(제한 없음)
타입 파라미터를 대치하는 구체적인 타입으로 모든 클래스나 인터페이스 타입이 올 수 있습니다.
제네릭 타입<? extends 상위 타입>: Upper Bounded Wildcards(상위 클래스 제한)
타입 파라미터를 대치하는 구체적인 타입으로 상위 타입이나 하위 타입이 올 수 있습니다.
제네릭 타입<? Super 하위 타입>: Lower Bounded Wildcards(하위 클래스 제한)타입
파라미터를 대치하는 구체적인 타입으로 하위 타입이나 상위타입이 올 수 있습니다.
Java 7부터는 generic type의 객체를 생성할 때 선언부에 타입 변수를 적었다면 instance 생성부에서는 타입 변수를 생략할 수도 있다. ( Box box<Integer> = new Box<>();)
Class
StringBuffer : 변하는 문자열을 다룰 때 사용
String 클래스의 객체는 한 번 생성되면 그 내용이 변하지 않는 반면에, StringBuffer 클래스의 객체는 한 번 생성된 후에도 계속하여 저장하고 있는 문자열의 내용을 변경할 수 있다.
Runtime : Runtime 인스턴스를 이용해 현 운영체제 시스템간의 상호 작용이 가능하다
Runtime 클래스를 이용해 외부의 프로그램을 사용할 수 있다. exe 메소드를 이용 하면된다.
Method
Process exec(String command) throws IOException : 새 프로세스를 만들어서 command에 명시된 명령어를 실행 시킨다. 이때 새로 만들어지는 프로세스는 현재 실행중인 프로세스와는 결개로 동작한다. 즉, 멀티태스킹이 구현된다.
RestTemplate : REST 서비스를 연동하기 위해 스프링에서 제공하는 객체 (Http method인 GET, POST, HEAD, OPTIONS, DELETE, PUT 메소드로 메세지를 전송할 수 있다.)
RestTemplate의 Http method에 따라 사용할 수 있는 메소드 종류
DELETE : delete()
GET : getForObject(), getForEntity()
HEAD : headForHeaders()
OPTIONS : optionsForAllow()
POST : postForLocation(), postForObject()
PUT : put()
any : exchange(), execute()
Method
getForObject() : It retrieves an entity using HTTP GET method on the given URL. (기본 Http Header를 사용하며 결과를 객체로 반환 받는다.)
exchange() : Executes the HTTP method for the given URI. It returns ResponseEntity. It can communicate using any HTTP method. (Http Header 를 수정할 수 있고 결과를 Http ResponseEntity로 반환 받는다.)
headForHeaders() : Retrieves all headers. It uses HTTP HEAD method.
getForEntity() : It retrieves an entity by using HTTP GET method for the given URL. (기본 Http Header를 사용하며 결과를 객체로 반환 받는다.)
delete() : Deletes the resources at the given URL. It uses HTTP DELETE method.
put(): It creates new resource or update for the given URL using HTTP PUT method.
postForObject(): It creates new resource using HTTP POST method and returns an entity.
postForLocation(): It creates new resource using HTTP POST method and returns the location of created new resource.
postForEntity(): It creates news resource using HTTP POST method to the given URI template. It returns
execute() : Request/Response 콜백을 수정할 수 있다.
flush() : 버퍼의 내용을 강제로 비움, close()하면 auto-flush 발생