[scala] 생성자 만들기 - not enough arguments for constructor DefaultConsumer
java의 Rabbitmq client library의 DefaultConsumer를 그냥 상속하면 다음 에러가 발생한다.
not enough arguments for constructor DefaultConsumer: (x$1: com.rabbitmq.client.Channel)com.rabbitmq.client.DefaultConsumer.
[error] Unspecified value parameter x$1.
[error] class Worker extends DefaultConsumer {
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
그 이유는 DefaultConsumer의 첫번째 아규먼트 인수를 무조건 받는 생성자를 가지고 있기 때문이다.
public class DefaultConsumer implements Consumer {
/** Channel that this consumer is associated with. */
private final Channel _channel;
/** Consumer tag for this consumer. */
private volatile String _consumerTag;
public DefaultConsumer(Channel channel) {
_channel = channel;
}
Scala에서는 아래와 같이 구현한다. 에러도 안나고, bolierplate 코드도 조금 없어지는 느낌이다.
class Worker(ch: Channel) extends DefaultConsumer(ch) {
val channel : Channel = ch
...
}