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
...
}
'scala' 카테고리의 다른 글
Play2/Play1 framework의 Schedule 작업 (0) | 2015.03.25 |
---|---|
play2 (scala) jmx 사용하기 (0) | 2014.12.22 |
scala (activator) 사용 팁 (0) | 2014.12.09 |
scala-sbt 주의할 점 - 개행 문자!! (0) | 2014.12.09 |
bad symbolic reference to scala.ScalaObject encountered in class file 'Logging.class' (0) | 2014.12.02 |